package com.iisigroup.adrclient.common;


import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JTextArea;


public class PartAddress {
	private List<String> spRoad=new ArrayList<String>();
	private List<String> postData=new ArrayList<String>();
	private boolean isSpecialRoad;
	private boolean isLevelOne;//level one 路 街 道 
	private int isRoadStrDao=0;//level one 道 
	private boolean isInPost;
	private boolean isSec;//段
	 // JDBC driver name and database URL
//	   private final String JDBC_DRIVER = "com.microsoft.sqlserver.jdbc.SQLServerDriver";  
	   //private final String DB_URL = "jdbc:sqlserver://192.168.6.53:1433;databaseName=AddrNorm";
//	   private final String DB_URL = "jdbc:sqlserver://localhost:1433;databaseName=Kaison_test";

	   //  Database credentials
//	   private final String USER = "sa";
//	   private final String PASS = "Ie@123456";
//	   private final String USER = "sa";
//	   private final String PASS = "A12345";
	private Properties prop = new Properties();
	private String JDBC_DRIVER;
	private String DB_URL;
	private String USER;
	private String PASS;
	
	public PartAddress() {
		try {
			prop.load(this.getClass().getClassLoader()
					.getResourceAsStream("datasource.properties"));
			JDBC_DRIVER = prop.getProperty("jdbc.driverClassName");
			DB_URL = prop.getProperty("jdbc.url");
			USER = prop.getProperty("jdbc.username");
			PASS = prop.getProperty("jdbc.password");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public void part(String searchYear, String countyCode, JTextArea console) {
		console.append("開始建立地址分欄結果...\n");
	   java.text.SimpleDateFormat df = new java.text.SimpleDateFormat();  
	   Connection conn = null;
	   Statement stmt = null;
	   Statement stmt2 = null;
	   Statement stmt3 = null;
	   Statement stmt4 = null;//更新post
	   PreparedStatement ps=null;
	   StringBuffer insertSql= null;
	   StringBuilder result=new StringBuilder();
//	   String COUNTRY="07";
	   int count=0;
	   int errorcount=0;
	   int totalcount=0;
	   console.append("正在查詢門牌及戶籍資料...\n");
	   try{
	      //STEP 2: Register JDBC driver
	      Class.forName(JDBC_DRIVER);

	      //STEP 3: Open a connection
	      System.out.println("Connecting to a selected database...");
	      conn = DriverManager.getConnection(DB_URL, USER, PASS);
	      System.out.println("Connected database successfully...");
	      
	      //STEP 4: Execute a query
	      System.out.println("Creating statement...");
	      stmt = conn.createStatement();
	      stmt2 = conn.createStatement();//insert
	      stmt3 = conn.createStatement();//query V_ADR_ADMAREA 縣市碼
	      stmt4 = conn.createStatement();//更新post

	      //String sql = "SELECT * FROM [dbo].[V_200_250_FULL_JOIN] where NEW_COUNTY_CODE='07' order by COUNTY_NAME,TOWN_NAME,NEW_VIL,NEW_NEIG";
	      StringBuilder sql=new StringBuilder();
	      sql.append("SELECT "); 
	      sql.append("case WHEN X.SOURCE_NO is not NULL THEN X.SOURCE_NO else RIGHT('0000000000' + LTRIM(RTRIM(CAST(Y.SERIAL AS [NCHAR]))), 10) end AS NEW_SOURCE_NO,");
	      sql.append("case WHEN Y.YEAR is not NULL THEN Y.YEAR else X.YEAR end AS NEW_YEAR,");
	      sql.append("case WHEN X.COUNTY_CODE is not NULL THEN X.COUNTY_CODE else Y.COUNTY_CODE end AS NEW_COUNTY_CODE,");
	      sql.append("X.ID,X.NAME,X.BIRTH,X.MARRIAGE,X.REL_MAST,X.MAST_ID,X.HUD_ID,X.ABORIGINE,X.REL_MAST_CODE,");
	      sql.append("case WHEN X.HH_CODE is not NULL THEN X.HH_CODE else Y.HH_CODE end AS NEW_HH_CODE,");
	      sql.append("X.MIX1,X.MIX2,X.MIX3,X.MOVE_IN,");
	      sql.append("case WHEN X.AREA_CODE is not NULL THEN X.AREA_CODE end AS NEW_AREA_CODE,");
	      sql.append("X.COUNTY_NAME,X.TOWN_NAME,Y.EDIT_TYPE,");
	      sql.append("case WHEN X.VIL is not NULL THEN X.VIL else Y.VIL end AS NEW_VIL,");
	      sql.append("case WHEN X.NEIG is not NULL THEN X.NEIG else Y.NEIG end AS NEW_NEIG,");
	      sql.append("case WHEN X.ADR1 is not NULL THEN X.ADR1 else Y.ADR2 end AS NEW_ADDRESS,");
	      sql.append("case WHEN Y.EDIT_DATE is not NULL THEN Y.EDIT_DATE end AS NEW_EDIT_DATE,");
	      sql.append("case WHEN X.ID is not NULL THEN '250' else '200' end AS SOURCE_FROM");
	      sql.append(" FROM ");
	      sql.append("(SELECT YEAR,SOURCE_NO,COUNTY_CODE,ID,NAME,BIRTH,MARRIAGE,REL_MAST,MAST_ID,HUD_ID,ABORIGINE,REL_MAST_CODE,HH_CODE,MIX1,MIX2,MIX3,MOVE_IN,AREA_CODE,COUNTY_NAME,TOWN_NAME,VIL,NEIG,ADDRESS AS ADR1 FROM HUD_250 WHERE COUNTY_CODE='"+countyCode+"' AND YEAR = '" + searchYear + "') X");
	      sql.append(" FULL JOIN ");
	      sql.append("(SELECT SERIAL,YEAR,COUNTY_CODE,HH_CODE,VIL,NEIG,ADDRESS AS ADR2,EDIT_DATE,EDIT_TYPE FROM ADR_200 WHERE COUNTY_CODE='"+countyCode+"' AND YEAR = '" + searchYear + "') Y ON X.ADR1 = Y.ADR2 AND X.VIL=Y.VIL AND X.NEIG=Y.NEIG ");
	      //sql.append(" where ADR1 like '%（%' or ADR2 like '%（%' and ADR1 LIKE'%全毀%' and ADR2 LIKE'%全毀%'");
	      //sql.append(" where X.ADR1 like N'%興農路二段４７４巷２弄２號%'  or Y.ADR2 like N'%興農路二段４７４巷２弄２號%'");
	      //sql.append("where ID is not null");
	      sql.append(" ORDER BY ID,COUNTY_NAME,TOWN_NAME,NEW_VIL,NEW_NEIG");
	      //System.out.println(sql.toString());
	      ResultSet rs = stmt.executeQuery(sql.toString());
	     
	      spRoad=getSpecialRoad();	      
	      postData=getPost();
	      //System.out.println("postData:"+postData);
	      
	      //STEP 5: Extract data from result set
	      System.out.println("輸入:"+ df.format(new Date()));
	      
		  insertSql =new StringBuffer();
	      insertSql.append("INSERT INTO ADR_380(SOURCE_NO,YEAR,COUNTY_CODE,ID,NAME,BIRTH,MARRIAGE,REL_MAST,");
		  insertSql.append("MAST_ID,HUD_ID,ABORIGINE,REL_MAST_CODE,HH_CODE,MIX1,MIX2,MIX3,MOVE_IN,AREA_CODE,COUNTY_NAME,");
		  insertSql.append("TOWN_NAME,VIL,NEIG,ADDRESS,STR,SEC,SEC_C,LAN,LAN_C,ALY,ALY_C,SUB_ALY,SUB_ALY_C,SP_CHAR1,NO1,DASH1,NO2,DASH2,");		                                                 
		  insertSql.append("NO3,NO_C,SP_CHAR2,NO4,SP_CHAR3,NO5,MAIN_FLOOR,FLOOR_C1,FLOOR_C2,SUB_FLOOR,ROOM,ROOM_C,COMMENT,ADR_MERGE,WEIGHT,WEIGHT2,ERR_CODE,EDIT_DATE,EDIT_TYPE)");
		  insertSql.append("VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,dbo.calWeight(?,?,?,?),dbo.calWeightOE(?,?,?,?),?,?,?)");
		  ps= conn.prepareStatement(insertSql.toString());
		  console.append("正在進行地址分欄作業...\n");
	      while(rs.next()){	
	    	  

	    	 isSec=false;
			 isSpecialRoad=false;
			 isLevelOne=false;
			 isInPost=false;
	         int ERR_CODE=-1;
	         count++;       
	        
	         String SOURCE_NO=null;
	         if (rs.getString("NEW_SOURCE_NO")!=null)
	        	 SOURCE_NO=rs.getString("NEW_SOURCE_NO").toString();
	         String YEAR=null;
	         if (rs.getString("NEW_YEAR")!=null)
	        	 YEAR=rs.getString("NEW_YEAR").toString();
	         String COUNTY_CODE=null;
	         
	         if (rs.getString("NEW_COUNTY_CODE")!=null)
	        	 COUNTY_CODE=rs.getString("NEW_COUNTY_CODE").toString();
	         String ID=null;
	         if (rs.getString("ID")!=null)
	         	 ID=rs.getString("ID").toString();
	         String NAME=null;
	         if (rs.getString("NAME")!=null)
	         	 NAME=rs.getString("NAME").toString();
	         String BIRTH=null;
	         if (rs.getString("BIRTH")!=null)
	        	 BIRTH=rs.getString("BIRTH").toString();
	         String MARRIAGE=null;
	         if (rs.getString("MARRIAGE")!=null)
	         	 MARRIAGE=rs.getString("MARRIAGE").toString();
	         String REL_MAST=null;
	         if (rs.getString("REL_MAST")!=null)
	         	 REL_MAST=rs.getString("REL_MAST").toString();
	         String MAST_ID=null;
	         if (rs.getString("MAST_ID")!=null)
	         	 MAST_ID=rs.getString("MAST_ID").toString();
	         String HUD_ID=null;
	         if (rs.getString("HUD_ID")!=null)
	         	 HUD_ID=rs.getString("HUD_ID").toString();
	         String ABORIGINE=null;
	         if (rs.getString("ABORIGINE")!=null)
	         	 ABORIGINE=rs.getString("ABORIGINE").toString();
	         String REL_MAST_CODE=null;
	         if (rs.getString("REL_MAST_CODE")!=null)
	         	 REL_MAST_CODE=rs.getString("REL_MAST_CODE").toString();
	         String HH_CODE=null;
	         if (rs.getString("NEW_HH_CODE")!=null)
	         	 HH_CODE=rs.getString("NEW_HH_CODE").toString();
	         String MIX1=null;
	         if (rs.getString("MIX1")!=null)
	         	 MIX1=rs.getString("MIX1").toString();
	         String MIX2=null;
	         if (rs.getString("MIX2")!=null)
	         	 MIX2=rs.getString("MIX2").toString();
	         String MIX3=null;
	         if (rs.getString("MIX3")!=null)
	         	 MIX3=rs.getString("MIX3").toString();
	         String MOVE_IN=null;
	         if (rs.getString("MOVE_IN")!=null)
	        	 MOVE_IN=rs.getString("MOVE_IN").toString();
	         String AREA_CODE=null;
	         if (rs.getString("NEW_AREA_CODE")!=null)
	         	 AREA_CODE=rs.getString("NEW_AREA_CODE").toString();
	         String COUNTY_NAME=null;
	         if (rs.getString("COUNTY_NAME")!=null)
	         	 COUNTY_NAME=rs.getString("COUNTY_NAME").toString();
	         String TOWN_NAME=null;
	         if (rs.getString("TOWN_NAME")!=null)
	         	 TOWN_NAME=rs.getString("TOWN_NAME").toString();
	         String VIL=null;
	         if (rs.getString("NEW_VIL")!=null)
	         	 VIL=rs.getString("NEW_VIL").toString();
	         String NEIG=null;
	         if (rs.getString("NEW_NEIG")!=null)
	         	 NEIG=rs.getString("NEW_NEIG").toString();
	         String ADDRESS=null;
	         if (rs.getString("NEW_ADDRESS")!=null)
	         	 ADDRESS=rs.getString("NEW_ADDRESS").toString();
	         String EDIT_DATE=null;
	         if (rs.getString("NEW_EDIT_DATE")!=null)
	         	 EDIT_DATE=rs.getString("NEW_EDIT_DATE").toString();
	         String EDIT_TYPE=null;
	         if (rs.getString("EDIT_TYPE")!=null)
	        	 EDIT_TYPE=rs.getString("EDIT_TYPE").toString();
	         String SOURCE_FROM=null;
	         	SOURCE_FROM=rs.getString("SOURCE_FROM").toString();
	         
	         				
	         
	         //System.out.print("COUNTY_CODE: " + COUNTY_CODE);
	         
	         if (SOURCE_NO!=null)
	        	 ps.setNString(1, rs.getString("NEW_SOURCE_NO").toString());
	         else
	        	 ps.setNull(1,Types.NCHAR);

	         if (YEAR!=null)
	         	 ps.setNString(2, rs.getString("NEW_YEAR").toString());
	         else
	        	 ps.setNull(2,Types.NCHAR);
	         
	         if (COUNTY_CODE!=null){
	        	 ps.setNString(3, rs.getString("NEW_COUNTY_CODE").toString());
	         }else{
	        	 //此解是台灣省 100表示台灣省
	        	 String hh_code=HH_CODE;
	        	 String str_city_code="";
	        	 if(hh_code.substring(0,3).equals("100")){
	        		 str_city_code=hh_code.substring(3,5);
	        		 COUNTY_CODE=hh_code.substring(3,5);
	        	 }
	        	 ps.setNString(3, str_city_code.toString());
	         }
	         
	         if (ID!=null)
	             ps.setNString(4, rs.getString("ID").toString());
	         else
	        	 ps.setNull(4,Types.NCHAR);
	         
	         if (NAME!=null)
	             ps.setNString(5, rs.getString("NAME").toString());
	         else
	        	 ps.setNull(5,Types.NVARCHAR);
	         
	         if (BIRTH!=null)
	        	 ps.setNString(6, rs.getString("BIRTH").toString());
	        else
	        	ps.setNull(6,Types.NCHAR);
	         
	         if (MARRIAGE!=null)
	             ps.setNString(7, rs.getString("MARRIAGE").toString());
	         else
	        	 ps.setNull(7,Types.NCHAR);
	         
	         if (REL_MAST!=null)
	        	 ps.setNString(8, rs.getString("REL_MAST").toString());
	         else
	        	 ps.setNull(8,Types.NVARCHAR);
	         
	         if (MAST_ID!=null)
	        	 ps.setNString(9, rs.getString("MAST_ID").toString());
	         else
	        	 ps.setNull(9,Types.NCHAR);
	         
	         if (HUD_ID!=null)
	         	 ps.setNString(10, rs.getString("HUD_ID").toString());
	         else
	        	 ps.setNull(10,Types.NCHAR);
	         
	         if (ABORIGINE!=null)
	         	ps.setNString(11, rs.getString("ABORIGINE").toString());
	         else
	        	 ps.setNull(11,Types.NCHAR);
	         
	         if (REL_MAST_CODE!=null)
	         	ps.setNString(12, rs.getString("REL_MAST_CODE").toString());
	         else
	        	 ps.setNull(12,Types.NCHAR);
	         
	         if (HH_CODE!=null)
	         	ps.setNString(13, rs.getString("NEW_HH_CODE").toString());
	         else
	        	 ps.setNull(13,Types.NCHAR);
	         
	         if (MIX1!=null)
	         	ps.setNString(14, rs.getString("MIX1").toString());
	         else
	        	 ps.setNull(14,Types.NCHAR);
	         
	         if (MIX2!=null)
	         	ps.setNString(15, rs.getString("MIX2").toString());
	         else
	        	 ps.setNull(15,Types.NCHAR);
	         
	         if (MIX3!=null)
	         	ps.setNString(16, rs.getString("MIX3").toString());
	         else
	        	 ps.setNull(16,Types.NCHAR);
	         
	         if (MOVE_IN!=null)
	         	ps.setNString(17, rs.getString("MOVE_IN").toString());
	         else
	        	 ps.setNull(17,Types.NCHAR);

	         if (AREA_CODE!=null){
	        	 ps.setNString(18, rs.getString("NEW_AREA_CODE").toString());
	         }else{
	        	 //用HH_CODE 轉AREA_CODE COUNTY_NAME TOWN_NAME
	        	 String area_code="";
	        	 String hh_code=HH_CODE;
	        	//此解是台灣省
	        	 String str_city_code="";
	        	 String str_citytown_code="";
	        	 if(hh_code.substring(0,3).equals("100")){
	        		 str_city_code=hh_code.substring(3,5);
	        		 str_citytown_code=hh_code.substring(5,7);
	        	 }
	        	 //SELECT CONCAT(CITY_CODE,CITYTOWN_CODE,VIL_CODE)  FROM [dbo].[V_ADR_ADMAREA] where CITY_CODE='15' and CITYTOWN_CODE='01' and VIL_NAME='民立里';
	        	 //String codeSQL="SELECT CONCAT(CITY_CODE,CITYTOWN_CODE,VIL_CODE)as area_code  FROM [dbo].[V_ADR_ADMAREA] ";
	        	 String codeSQL="SELECT CONCAT(COUNTY_CODE,TOWN_CODE,VIL_CODE)as area_code,COUNTY_NAME,TOWN_NAME FROM [dbo].[ADR_AREA] ";
	        	 codeSQL+="where COUNTY_CODE='"+str_city_code+"' AND";
	        	 codeSQL+=" TOWN_CODE='"+str_citytown_code+"' AND";
	        	 codeSQL+=" VIL_NAME=N'"+rs.getString("NEW_VIL")+"'";
	        	 
	        	 ResultSet rs3 = stmt3.executeQuery(codeSQL);
	        	 //System.out.println("codeSQL"+codeSQL);
	        	 while (rs3.next()){
	        		 area_code=rs3.getString("area_code");
	        		 COUNTY_NAME=rs3.getString("COUNTY_NAME");
	        		 TOWN_NAME=rs3.getString("TOWN_NAME");
	        	 }
	        	 AREA_CODE=area_code+rs.getString("NEW_NEIG");
	        	 ps.setNString(18, AREA_CODE.toString());
	         }
	         //System.out.println("SOURCE_FROM="+SOURCE_FROM);
//	         System.out.println("AREA_CODE="+AREA_CODE);

	         
	         //System.out.println("COUNTY_NAME="+COUNTY_NAME);
	         if (COUNTY_NAME!=null){
	        	 ps.setNString(19, COUNTY_NAME);
	         }else{
//	        	 String city_name="";
//	        	 String hh_code=HH_CODE;
//	        	 //此解是台灣省
//	        	 String str_city_code="";
//	        	 if(hh_code.substring(0,3).equals("100")){//	        		 str_city_code=hh_code.substring(3,5);
//	        	 }
//	        	 String codeSQL="SELECT DISTINCT COUNTY_NAME  FROM [dbo].[ADR_AREA] where COUNTY_CODE=";
//	        	 codeSQL+="'"+str_city_code+"'";
//	        	 ResultSet rs3 = stmt3.executeQuery(codeSQL);
//	        	 while (rs3.next()){
//	        		 city_name=rs3.getString("COUNTY_NAME");
//	        	 }
//	        	 COUNTY_NAME=city_name;
//	        	 //System.out.println("COUNTY_NAME="+COUNTY_NAME);
//	        	 insertSql.append("N'"+COUNTY_NAME+"',");

	         }
	         //System.out.println("COUNTY_NAME="+COUNTY_NAME);
	         
	         
	         //System.out.println("TOWN_NAME="+TOWN_NAME);
	         if (TOWN_NAME!=null){
	        	 ps.setNString(20, TOWN_NAME);
	         }else{
//	        	 String town_name="";
//	        	 String hh_code=HH_CODE;
//	        	 //此解是台灣省
//	        	 String str_city_code=hh_code.substring(3,5);
//	        	 String str_citytown_code=hh_code.substring(5,7);
//	        	 String codeSQL="SELECT DISTINCT TOWN_NAME  FROM [dbo].[ADR_AREA] where COUNTY_CODE=";
//	        	 codeSQL+="'"+str_city_code+"'";
//	        	 codeSQL+=" and TOWN_CODE=";
//	        	 codeSQL+="'"+str_citytown_code+"'";
//	        	 ResultSet rs3 = stmt3.executeQuery(codeSQL);
//	        	 while (rs3.next()){
//	        		 town_name=rs3.getString("TOWN_NAME");
//	        	 }
//	        	 TOWN_NAME=town_name;
//	        	 insertSql.append("N'"+TOWN_NAME+"',");

	         }
	         
	         if (VIL!=null)
	         	 ps.setNString(21, rs.getString("NEW_VIL").toString());
	         else
	        	 ps.setNull(21,Types.NVARCHAR);
	         
	         if (NEIG!=null)
	         	ps.setNString(22, rs.getString("NEW_NEIG").toString());
	         else
	        	 ps.setNull(22,Types.NVARCHAR);
	         
	         if (ADDRESS!=null)
	         	 ps.setNString(23, rs.getString("NEW_ADDRESS").toString());
	         else
	        	 ps.setNull(23,Types.NVARCHAR);


	         
	         //System.out.println("ADDRESS:"+ADDRESS);
	         if (ADDRESS==null){
	        	 //System.out.println("ADDRESS 是空的:"+ADDRESS);	        	 //STR,SEC,SEC_C,LAN,LAN_C,ALY,ALY_C,SUB_ALY,SUB_ALY_C,SP_CHAR1,NO1,DASH1,NO2,DASH2,NO3,NO_C,SP_CHAR2,NO4,SP_CHAR3,NO5,MAIN_FLOOR,FLOOR_C1,FLOOR_C2,SUB_FLOOR,ROOM,ROOM_C,COMMENT,ADR_MERGE,WEIGHT,WEIGHT2
	        	 ps.setNull(24,Types.NVARCHAR);//STR
	        	 ps.setNull(25,Types.NVARCHAR);//SEC
	        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
	        	 ps.setNull(27,Types.NVARCHAR);//LAN
	        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
	        	 ps.setNull(29,Types.NVARCHAR);//ALY
	        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
	        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
	        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
	        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
	        	 ps.setNull(34,Types.NVARCHAR);//NO1
	        	 ps.setNull(35,Types.NCHAR);//DASH1
	        	 ps.setNull(36,Types.NVARCHAR);//NO2
	        	 ps.setNull(37,Types.NCHAR);//DASH2
	        	 ps.setNull(38,Types.NVARCHAR);//NO3
	        	 ps.setNull(39,Types.NCHAR);//NO_C
	        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
	        	 ps.setNull(41,Types.NVARCHAR);//NO4
	        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
	        	 ps.setNull(43,Types.NVARCHAR);//NO5
	        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
	        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
	        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
	        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
	        	 ps.setNull(48,Types.NVARCHAR);//ROOM
	        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
	        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
	        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
	        	 ps.setNull(52,Types.NVARCHAR);//Lan
	        	 ps.setNull(53,Types.NVARCHAR);//Aly
	        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
	        	 ps.setNull(55,Types.NVARCHAR);//no1
	        	 ps.setNull(56,Types.NVARCHAR);//Lan
	        	 ps.setNull(57,Types.NVARCHAR);//Aly
	        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
	        	 ps.setNull(59,Types.NVARCHAR);//no1
	        	 
	        	 ERR_CODE=1;//地址是空的
	        	 errorcount++;
	        	 count--;
	         }else{
	        	if (!ADDRESS.contains("號")){
	        		//System.out.println("ADDRESS 不含號:"+ADDRESS);
		        	 ps.setNull(24,Types.NVARCHAR);//STR
		        	 ps.setNull(25,Types.NVARCHAR);//SEC
		        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
		        	 ps.setNull(27,Types.NVARCHAR);//LAN
		        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
		        	 ps.setNull(29,Types.NVARCHAR);//ALY
		        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
		        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
		        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
		        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
		        	 ps.setNull(34,Types.NVARCHAR);//NO1
		        	 ps.setNull(35,Types.NCHAR);//DASH1
		        	 ps.setNull(36,Types.NVARCHAR);//NO2
		        	 ps.setNull(37,Types.NCHAR);//DASH2
		        	 ps.setNull(38,Types.NVARCHAR);//NO3
		        	 ps.setNull(39,Types.NCHAR);//NO_C
		        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
		        	 ps.setNull(41,Types.NVARCHAR);//NO4
		        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
		        	 ps.setNull(43,Types.NVARCHAR);//NO5
		        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
		        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
		        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
		        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
		        	 ps.setNull(48,Types.NVARCHAR);//ROOM
		        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
		        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
		        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
		        	 ps.setNull(52,Types.NVARCHAR);//Lan
		        	 ps.setNull(53,Types.NVARCHAR);//Aly
		        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
		        	 ps.setNull(55,Types.NVARCHAR);//no1
		        	 ps.setNull(56,Types.NVARCHAR);//Lan
		        	 ps.setNull(57,Types.NVARCHAR);//Aly
		        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
		        	 ps.setNull(59,Types.NVARCHAR);//no1
	        		ERR_CODE=2;//不含號
	        		errorcount++;
	        		count--;
	        	}else{
	        		if (!ADDRESS.contains("戶政事務所") && !ADDRESS.contains("拆除") && !ADDRESS.contains("戶政所") && !ADDRESS.contains("折除")&&!ADDRESS.contains("全毀")){
//	        			System.out.println("ADDRESS:"+ADDRESS);
//	        			System.out.println("isContainNEIG(ADDRESS):"+isContainNEIG(ADDRESS));
	        			//System.out.println("isExtChar(ADDRESS):"+isExtChar(ADDRESS));
	        			if (!isExtChar(ADDRESS)){
		        			if(!isContainNEIG(ADDRESS)){//是否有鄰
		        				//System.out.println("isContainTwoSec:"+isContainTwoSec(ADDRESS));
			        			if ((!isContainTwoNum(ADDRESS)) && (!isContainTwoSec(ADDRESS)) && (!isContainTwoRoad(ADDRESS))){//是否有2個號2個段2個路
			        				    //System.out.println("ADDRESS:"+ADDRESS);
				        				//System.out.print("可分割地址"+COUNTY_NAME+TOWN_NAME+ADDRESS);
				        				String partAddr=doJob(COUNTY_NAME+","+TOWN_NAME+","+ADDRESS);//doJob
				        				//System.out.print("partAddr: " + partAddr +"\n");
				        				String[] addr=partAddr.split(",", -1);  
				        				StringBuffer subStr=new StringBuffer();//可分割的26個位置欄位
				        				StringBuffer subStr2=new StringBuffer();//可分割的組合地址
				        				StringBuffer subStr3=new StringBuffer();//Post檔比較地址只到弄0~3
				        				StringBuffer subStr3_2=new StringBuffer();//Post檔比較地址只到弄0~3 加,
				        				
				        				//System.out.print("isContainSec:"+isNumSec(ADDRESS));
				        				//System.out.print("isContainSec:"+!addr[0].toString().equals(""));
				        				
				        		    if(isNumSec(ADDRESS) && (!addr[0].toString().equals("")) || (!isNumSec(ADDRESS))){
				        		    	
				        		    	
				        		    	if (!ADDRESS.equals("復興里臨２７９號")&&!ADDRESS.equals("５８之６號")&&!ADDRESS.equals("５８之２號") && !ADDRESS.equals("文開路３２５號") && !ADDRESS.equals("彰水路四段鄰２０８號")){//特殊例子無解
				        		    		//地址有數字段但卻無路也視為error
					        				for(int i=0;i<addr.length;i++){
					        					//System.out.print("addr: " + addr[i] +"\n");
					        					//System.out.print("addr length: " + addr[i].length() +"\n");
					        					//if (addr[i]!=null){	
					        					if (!addr[i].toString().equals("")){	
					        						//subStr.append("N'"+addr[i]+"',");   
					        						subStr.append(addr[i]+",");   
					        						if (i<=6){	
					        							subStr3_2.append("N'"+addr[i]+"',");  
//					        							subStr3_2.append(addr[i]+","); 
					        						}
					             					//System.out.print("addr: " + addr[i] +"\n");
						        					//System.out.print("addr length: " + addr[i].length() +"\n");
						        						if(addr[i].length()!=0){		
//						        							System.out.println("addr[i]: " + addr[i]);
//						        							System.out.println("i=: " + i);
						        						if (i<=6){				        						
						        							subStr2.append(addr[i]);  
						        							subStr3.append(addr[i]);  
						        						}else{
						        							subStr2.append(addr[i]);  
						        						}
						        					}
					        					}else{
					        						subStr.append("NULL,"); 
					        						if (i<=6){	
					        							subStr3_2.append("NULL,");   
					        						}
					        					}					        					
					        				}
					        				
					        				
//					        				System.out.println("address:"+ADDRESS);
//					        				System.out.println("subStr:"+subStr);
//					        				System.out.println("subStr2:"+subStr2);//merge
//					        				System.out.println("subStr3:"+subStr3);//post 比較
//					        				System.out.println("subStr3_2:"+subStr3_2.substring(0,subStr3_2.lastIndexOf(",")));
					        				
					        				//比較post  SELECT CONCAT(AREA_TOWN,ADR_ALY) as keyword  FROM [dbo].[ADR_POST]; 縣市別+鄉鎮市區代號+subStr3
					        				String comparData="";
					        				String str_city_code="";
					        				String str_citytown_code="";
					        				String hh_code=HH_CODE;
						       	        	if(hh_code.substring(0,3).equals("100")){
						    	        		 str_city_code=hh_code.substring(3,5);
						    	        		 str_citytown_code=hh_code.substring(5,7);
						    	        	 }
					        				comparData+=str_city_code+str_citytown_code+subStr3;//只到弄
					        				//System.out.println("comparData:"+comparData);
//					        				System.out.println("isInPost:"+isInPost);
					        				if (comparData.equals("")){
					        					isInPost=true;
					        				}else{
						        				for(String str:postData){
						        					if (comparData.equals(str)){
						        						isInPost=true;
						        						break;
						        					}
						        				}
					        				}
					        				//System.out.println("isInPost:"+isInPost);
					        				
					        				if(isInPost){
					        					//在Post裡面-->正常地址
//					        					System.out.println("InPost ADDRES:"+ADDRESS);
					        					//System.out.println("subStr:"+subStr);
					        					//System.out.println("subStr2:"+subStr2);
						        				 String[] subStrs=subStr.toString().split(",");
						        				
						        				 if (!subStrs[0].equals("NULL"))
						        					 ps.setNString(24,subStrs[0]);//STR
						        				 else 
						        					 ps.setNull(24,Types.NVARCHAR);//STR
						        				 
						        				 if (!subStrs[1].equals("NULL"))
						        					 ps.setNString(25,subStrs[1]);
						        				 else 
						        					 ps.setNull(25,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[2].equals("NULL"))
						        					 ps.setNString(26,subStrs[2]);
						        				 else 
						        					 ps.setNull(26,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[3].equals("NULL"))
						        					 ps.setNString(27,subStrs[3]);
						        				 else 
						        					 ps.setNull(27,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[4].equals("NULL"))
						        					 ps.setNString(28,subStrs[4]);
						        				 else 
						        					 ps.setNull(28,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[5].equals("NULL"))
						        					 ps.setNString(29,subStrs[5]);
						        				 else 
						        					 ps.setNull(29,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[6].equals("NULL"))
						        					 ps.setNString(30,subStrs[6]);
						        				 else 
						        					 ps.setNull(30,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[7].equals("NULL"))
						        					 ps.setNString(31,subStrs[7]);
						        				 else 
						        					 ps.setNull(31,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[8].equals("NULL"))
						        					 ps.setNString(32,subStrs[8]);
						        				 else 
						        					 ps.setNull(32,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[9].equals("NULL"))
						        					 ps.setNString(33,subStrs[9]);
						        				 else 
						        					 ps.setNull(33,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[10].equals("NULL"))
						        					 ps.setNString(34,subStrs[10]);
						        				 else 
						        					 ps.setNull(34,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[11].equals("NULL"))
						        					 ps.setNString(35,subStrs[11]);
						        				 else 
						        					 ps.setNull(35,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[12].equals("NULL"))
						        					 ps.setNString(36,subStrs[12]);
						        				 else 
						        					 ps.setNull(36,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[13].equals("NULL"))
						        					 ps.setNString(37,subStrs[13]);
						        				 else 
						        					 ps.setNull(37,Types.NVARCHAR);
						        				 
						        				 
						        				 if (!subStrs[14].equals("NULL"))
						        					 ps.setNString(38,subStrs[14]);
						        				 else 
						        					 ps.setNull(38,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[15].equals("NULL"))
						        					 ps.setNString(39,subStrs[15]);
						        				 else 
						        					 ps.setNull(39,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[16].equals("NULL"))
						        					 ps.setNString(40,subStrs[16]);
						        				 else 
						        					 ps.setNull(40,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[17].equals("NULL"))
						        					 ps.setNString(41,subStrs[17]);
						        				 else 
						        					 ps.setNull(41,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[18].equals("NULL"))
						        					 ps.setNString(42,subStrs[18]);
						        				 else 
						        					 ps.setNull(42,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[19].equals("NULL"))
						        					 ps.setNString(43,subStrs[19]);
						        				 else 
						        					 ps.setNull(43,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[20].equals("NULL"))
						        					 ps.setNString(44,subStrs[20]);
						        				 else 
						        					 ps.setNull(44,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[21].equals("NULL"))
						        					 ps.setNString(45,subStrs[21]);
						        				 else 
						        					 ps.setNull(45,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[22].equals("NULL"))
						        					 ps.setNString(46,subStrs[22]);
						        				 else 
						        					 ps.setNull(46,Types.NVARCHAR);


						        				 if (!subStrs[23].equals("NULL"))
						        					 ps.setNString(47,subStrs[23]);
						        				 else 
						        					 ps.setNull(47,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[24].equals("NULL"))
						        					 ps.setNString(48,subStrs[24]);
						        				 else 
						        					 ps.setNull(48,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[25].equals("NULL"))
						        					 ps.setNString(49,subStrs[25]);
						        				 else 
						        					 ps.setNull(49,Types.NVARCHAR);
						        				 
						        				 if (!subStrs[26].equals("NULL"))
						        					 ps.setNString(50,subStrs[26]);
						        				 else 
						        					 ps.setNull(50,Types.NVARCHAR);

			        				        	 ps.setNString(51,subStr2.toString());//ADR_MERGE
			        				        	 
			        				        	 
												//WEIGHT(lan,aly,sub_aly,no1)//2015/02/21 kaison 增加weight
			        				        	 if (!subStrs[3].equals("NULL"))
						        					 ps.setNString(52,subStrs[3]);//LAN
						        				 else 
						        					 ps.setNull(52,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[5].equals("NULL"))
						        					 ps.setNString(53,subStrs[5]);//ALY
						        				 else 
						        					 ps.setNull(53,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[7].equals("NULL"))
						        					 ps.setNString(54,subStrs[7]);//SUB_ALY
						        				 else 
						        					 ps.setNull(54,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[10].equals("NULL"))
						        					 ps.setNString(55,subStrs[10]);//NO1
						        				 else 
						        					 ps.setNull(55,Types.NVARCHAR);
			        				        	 //WEIGHT2(lan,aly,sub_aly,no1)
		        				        	 
			        				        	 if (!subStrs[3].equals("NULL"))
						        					 ps.setNString(56,subStrs[3]);//LAN
						        				 else 
						        					 ps.setNull(56,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[5].equals("NULL"))
						        					 ps.setNString(57,subStrs[5]);//ALY
						        				 else 
						        					 ps.setNull(57,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[7].equals("NULL"))
						        					 ps.setNString(58,subStrs[7]);//SUB_ALY
						        				 else 
						        					 ps.setNull(58,Types.NVARCHAR);
			        				        	 
			        				        	 if (!subStrs[10].equals("NULL"))
						        					 ps.setNString(59,subStrs[10]);//NO1
						        				 else 
						        					 ps.setNull(59,Types.NVARCHAR);
					        				}else{
					        					//不在post			        					
					        					//if 200門牌 看Year EditDate
					        					if (SOURCE_FROM.equals("200")){
					        						int year=Integer.parseInt(YEAR);
					        						if (!EDIT_DATE.equals("       ")){
					        							int editYear=Integer.parseInt(EDIT_DATE.substring(0, 3));
					        							//System.out.println("year:"+year+"//editYear:"+editYear);

						        						if (editYear>=year-2){
						        							//視為正常可分割 但要更新Post檔
						        							//System.out.println("視為正常可分割 但要更新Post檔:"+subStr3_2);						        							
									        				 String[] subStrs=subStr.toString().split(",");
										        			//STR,SEC,SEC_C,LAN,LAN_C,ALY,ALY_C,SUB_ALY,SUB_ALY_C,SP_CHAR1,NO1	
									        				 if (!subStrs[0].equals("NULL"))
									        					 ps.setNString(24,subStrs[0]);//STR
									        				 else 
									        					 ps.setNull(24,Types.NVARCHAR);//STR
									        				 
									        				 if (!subStrs[1].equals("NULL"))
									        					 ps.setNString(25,subStrs[1]);//SEC
									        				 else 
									        					 ps.setNull(25,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[2].equals("NULL"))
									        					 ps.setNString(26,subStrs[2]);//SEC_C
									        				 else 
									        					 ps.setNull(26,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[3].equals("NULL"))
									        					 ps.setNString(27,subStrs[3]);//LAN
									        				 else 
									        					 ps.setNull(27,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[4].equals("NULL"))
									        					 ps.setNString(28,subStrs[4]);//LAN_C
									        				 else 
									        					 ps.setNull(28,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[5].equals("NULL"))
									        					 ps.setNString(29,subStrs[5]);//ALY
									        				 else 
									        					 ps.setNull(29,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[6].equals("NULL"))
									        					 ps.setNString(30,subStrs[6]);//ALY_C
									        				 else 
									        					 ps.setNull(30,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[7].equals("NULL"))
									        					 ps.setNString(31,subStrs[7]);//SUB_ALY
									        				 else 
									        					 ps.setNull(31,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[8].equals("NULL"))
									        					 ps.setNString(32,subStrs[8]);//SUB_ALY_C
									        				 else 
									        					 ps.setNull(32,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[9].equals("NULL"))
									        					 ps.setNString(33,subStrs[9]);//SP_CHAR1
									        				 else 
									        					 ps.setNull(33,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[10].equals("NULL"))
									        					 ps.setNString(34,subStrs[10]);//NO1
									        				 else 
									        					 ps.setNull(34,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[11].equals("NULL"))
									        					 ps.setNString(35,subStrs[11]);
									        				 else 
									        					 ps.setNull(35,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[12].equals("NULL"))
									        					 ps.setNString(36,subStrs[12]);
									        				 else 
									        					 ps.setNull(36,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[13].equals("NULL"))
									        					 ps.setNString(37,subStrs[13]);
									        				 else 
									        					 ps.setNull(37,Types.NVARCHAR);
									        				 
									        				 
									        				 if (!subStrs[14].equals("NULL"))
									        					 ps.setNString(38,subStrs[14]);
									        				 else 
									        					 ps.setNull(38,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[15].equals("NULL"))
									        					 ps.setNString(39,subStrs[15]);
									        				 else 
									        					 ps.setNull(39,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[16].equals("NULL"))
									        					 ps.setNString(40,subStrs[16]);
									        				 else 
									        					 ps.setNull(40,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[17].equals("NULL"))
									        					 ps.setNString(41,subStrs[17]);
									        				 else 
									        					 ps.setNull(41,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[18].equals("NULL"))
									        					 ps.setNString(42,subStrs[18]);
									        				 else 
									        					 ps.setNull(42,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[19].equals("NULL"))
									        					 ps.setNString(43,subStrs[19]);
									        				 else 
									        					 ps.setNull(43,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[20].equals("NULL"))
									        					 ps.setNString(44,subStrs[20]);
									        				 else 
									        					 ps.setNull(44,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[21].equals("NULL"))
									        					 ps.setNString(45,subStrs[21]);
									        				 else 
									        					 ps.setNull(45,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[22].equals("NULL"))
									        					 ps.setNString(46,subStrs[22]);
									        				 else 
									        					 ps.setNull(46,Types.NVARCHAR);


									        				 if (!subStrs[23].equals("NULL"))
									        					 ps.setNString(47,subStrs[23]);
									        				 else 
									        					 ps.setNull(47,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[24].equals("NULL"))
									        					 ps.setNString(48,subStrs[24]);
									        				 else 
									        					 ps.setNull(48,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[25].equals("NULL"))
									        					 ps.setNString(49,subStrs[25]);
									        				 else 
									        					 ps.setNull(49,Types.NVARCHAR);
									        				 
									        				 if (!subStrs[26].equals("NULL"))
									        					 ps.setNString(50,subStrs[26]);
									        				 else 
									        					 ps.setNull(50,Types.NVARCHAR);

						        				        	 ps.setNString(51,subStr2.toString());//ADR_MERGE
															//WEIGHT(lan,aly,sub_aly,no1)//2015/02/21 kaison 增加weight
						        				        	 if (!subStrs[3].equals("NULL"))
									        					 ps.setNString(52,subStrs[3]);//LAN
									        				 else 
									        					 ps.setNull(52,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[5].equals("NULL"))
									        					 ps.setNString(53,subStrs[5]);//ALY
									        				 else 
									        					 ps.setNull(53,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[7].equals("NULL"))
									        					 ps.setNString(54,subStrs[7]);//SUB_ALY
									        				 else 
									        					 ps.setNull(54,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[10].equals("NULL"))
									        					 ps.setNString(55,subStrs[10]);//NO1
									        				 else 
									        					 ps.setNull(55,Types.NVARCHAR);
						        				        	 //WEIGHT2(lan,aly,sub_aly,no1)
						        				        	 if (!subStrs[3].equals("NULL"))
									        					 ps.setNString(56,subStrs[3]);//LAN
									        				 else 
									        					 ps.setNull(56,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[5].equals("NULL"))
									        					 ps.setNString(57,subStrs[5]);//ALY
									        				 else 
									        					 ps.setNull(57,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[7].equals("NULL"))
									        					 ps.setNString(58,subStrs[7]);//SUB_ALY
									        				 else 
									        					 ps.setNull(58,Types.NVARCHAR);
						        				        	 
						        				        	 if (!subStrs[10].equals("NULL"))
									        					 ps.setNString(59,subStrs[10]);//NO1
									        				 else 
									        					 ps.setNull(59,Types.NVARCHAR);
						        							
						        							//寫回POST檔
															//System.out.print("sssss"+COUNTY_NAME+TOWN_NAME+ADDRESS);
						        							StringBuilder insertPostSql =new StringBuilder();
						        							insertPostSql.append("INSERT INTO ADR_POST (YEAR,COUNTY_CODE,AREA_TOWN,COUNTY_NAME,TOWN_NAME,STR,SEC,SEC_C,LAN,LAN_C,ALY,ALY_C,ADR_ALY)");
						        							insertPostSql.append("VALUES(");
						        							insertPostSql.append("N'"+YEAR+"',N'"+COUNTY_CODE+"',N'"+HH_CODE.substring(3,7)+"',N'"+COUNTY_NAME+"',N'"+TOWN_NAME+"',");
						        							insertPostSql.append(subStr3_2.substring(0,subStr3_2.lastIndexOf(","))+",");
						        							insertPostSql.append("N'"+subStr3+"')");
						        							System.out.println("insertPostSql:"+insertPostSql.toString());
						        							//System.out.println("postData:"+postData.size());
						        							stmt4.execute(insertPostSql.toString());
						        							//2015/02/06 暫時未加入\
						        							conn.commit();
						        							postData.clear();
						        							postData=getPost();
						        							//System.out.println("postData:"+postData.size());
						        						}else{
			//				        						System.out.println("不在POST:"+subStr3+"//source_from:"+SOURCE_FROM);
			//				        						System.out.println("ADRESS:"+ADDRESS);
			//				        						System.out.println("year:"+year+"//editYear:"+editYear);
						        				        	 ps.setNull(24,Types.NVARCHAR);//STR
						        				        	 ps.setNull(25,Types.NVARCHAR);//SEC
						        				        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
						        				        	 ps.setNull(27,Types.NVARCHAR);//LAN
						        				        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
						        				        	 ps.setNull(29,Types.NVARCHAR);//ALY
						        				        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
						        				        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
						        				        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
						        				        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
						        				        	 ps.setNull(34,Types.NVARCHAR);//NO1
						        				        	 ps.setNull(35,Types.NCHAR);//DASH1
						        				        	 ps.setNull(36,Types.NVARCHAR);//NO2
						        				        	 ps.setNull(37,Types.NCHAR);//DASH2
						        				        	 ps.setNull(38,Types.NVARCHAR);//NO3
						        				        	 ps.setNull(39,Types.NCHAR);//NO_C
						        				        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
						        				        	 ps.setNull(41,Types.NVARCHAR);//NO4
						        				        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
						        				        	 ps.setNull(43,Types.NVARCHAR);//NO5
						        				        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
						        				        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
						        				        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
						        				        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
						        				        	 ps.setNull(48,Types.NVARCHAR);//ROOM
						        				        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
						        				        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
						        				        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
						        				        	 ps.setNull(52,Types.NVARCHAR);//Lan
						        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
						        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
						        				        	 ps.setNull(55,Types.NVARCHAR);//no1
						        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
						        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
						        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
						        				        	 ps.setNull(59,Types.NVARCHAR);//no1
						        							ERR_CODE=8;//不在POST 200
							    	        				errorcount++;
							    		        			count--;
						        						}
					        						}else{
					        				        	 ps.setNull(24,Types.NVARCHAR);//STR
					        				        	 ps.setNull(25,Types.NVARCHAR);//SEC
					        				        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
					        				        	 ps.setNull(27,Types.NVARCHAR);//LAN
					        				        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
					        				        	 ps.setNull(29,Types.NVARCHAR);//ALY
					        				        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
					        				        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
					        				        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
					        				        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
					        				        	 ps.setNull(34,Types.NVARCHAR);//NO1
					        				        	 ps.setNull(35,Types.NCHAR);//DASH1
					        				        	 ps.setNull(36,Types.NVARCHAR);//NO2
					        				        	 ps.setNull(37,Types.NCHAR);//DASH2
					        				        	 ps.setNull(38,Types.NVARCHAR);//NO3
					        				        	 ps.setNull(39,Types.NCHAR);//NO_C
					        				        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
					        				        	 ps.setNull(41,Types.NVARCHAR);//NO4
					        				        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
					        				        	 ps.setNull(43,Types.NVARCHAR);//NO5
					        				        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
					        				        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
					        				        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
					        				        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
					        				        	 ps.setNull(48,Types.NVARCHAR);//ROOM
					        				        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
					        				        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
					        				        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
					        				        	 ps.setNull(52,Types.NVARCHAR);//Lan
					        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
					        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
					        				        	 ps.setNull(55,Types.NVARCHAR);//no1
					        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
					        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
					        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
					        				        	 ps.setNull(59,Types.NVARCHAR);//no1
					        							ERR_CODE=9;//不在POST 200 且edit_date 為空
						    	        				errorcount++;
						    		        			count--;
					        						}
					        					}else{
					        						//System.out.println("ADDRESS 地址不正常:"+ADDRESS);
						        			         ps.setNull(24,Types.NVARCHAR);//STR
					        			        	 ps.setNull(25,Types.NVARCHAR);//SEC
					        			        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
					        			        	 ps.setNull(27,Types.NVARCHAR);//LAN
					        			        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
					        			        	 ps.setNull(29,Types.NVARCHAR);//ALY
					        			        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
					        			        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
					        			        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
					        			        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
					        			        	 ps.setNull(34,Types.NVARCHAR);//NO1
					        			        	 ps.setNull(35,Types.NCHAR);//DASH1
					        			        	 ps.setNull(36,Types.NVARCHAR);//NO2
					        			        	 ps.setNull(37,Types.NCHAR);//DASH2
					        			        	 ps.setNull(38,Types.NVARCHAR);//NO3
					        			        	 ps.setNull(39,Types.NCHAR);//NO_C
					        			        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
					        			        	 ps.setNull(41,Types.NVARCHAR);//NO4
					        			        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
					        			        	 ps.setNull(43,Types.NVARCHAR);//NO5
					        			        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
					        			        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
					        			        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
					        			        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
					        			        	 ps.setNull(48,Types.NVARCHAR);//ROOM
					        			        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
					        			        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
					        			        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
					        			        	 ps.setNull(52,Types.NVARCHAR);//Lan
				        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
				        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
				        				        	 ps.setNull(55,Types.NVARCHAR);//no1
				        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
				        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
				        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
				        				        	 ps.setNull(59,Types.NVARCHAR);//no1
					        						ERR_CODE=7;//不在POST 250
					    	        				errorcount++;
					    		        			count--;
					        					}
					        				}

				        		    	}else{
				        		    		//System.out.println("ADDRESS 地址不正常:"+ADDRESS);
				        		        	 ps.setNull(24,Types.NVARCHAR);//STR
				        		        	 ps.setNull(25,Types.NVARCHAR);//SEC
				        		        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
				        		        	 ps.setNull(27,Types.NVARCHAR);//LAN
				        		        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
				        		        	 ps.setNull(29,Types.NVARCHAR);//ALY
				        		        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
				        		        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
				        		        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
				        		        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
				        		        	 ps.setNull(34,Types.NVARCHAR);//NO1
				        		        	 ps.setNull(35,Types.NCHAR);//DASH1
				        		        	 ps.setNull(36,Types.NVARCHAR);//NO2
				        		        	 ps.setNull(37,Types.NCHAR);//DASH2
				        		        	 ps.setNull(38,Types.NVARCHAR);//NO3
				        		        	 ps.setNull(39,Types.NCHAR);//NO_C
				        		        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
				        		        	 ps.setNull(41,Types.NVARCHAR);//NO4
				        		        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
				        		        	 ps.setNull(43,Types.NVARCHAR);//NO5
				        		        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
				        		        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
				        		        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
				        		        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
				        		        	 ps.setNull(48,Types.NVARCHAR);//ROOM
				        		        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
				        		        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
				        		        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
				        		        	 ps.setNull(52,Types.NVARCHAR);//Lan
		        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
		        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
		        				        	 ps.setNull(55,Types.NVARCHAR);//no1
		        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
		        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
		        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
		        				        	 ps.setNull(59,Types.NVARCHAR);//no1
				        		    		ERR_CODE=6;//地址不正常
					        				errorcount++;
					        				count--;
				        		    	}
				        		    	
				        		    }else{
			        					//System.out.println("ADDRESS 地址不正常:"+ADDRESS);
					       	        	 ps.setNull(24,Types.NVARCHAR);//STR
					    	        	 ps.setNull(25,Types.NVARCHAR);//SEC
					    	        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
					    	        	 ps.setNull(27,Types.NVARCHAR);//LAN
					    	        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
					    	        	 ps.setNull(29,Types.NVARCHAR);//ALY
					    	        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
					    	        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
					    	        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
					    	        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
					    	        	 ps.setNull(34,Types.NVARCHAR);//NO1
					    	        	 ps.setNull(35,Types.NCHAR);//DASH1
					    	        	 ps.setNull(36,Types.NVARCHAR);//NO2
					    	        	 ps.setNull(37,Types.NCHAR);//DASH2
					    	        	 ps.setNull(38,Types.NVARCHAR);//NO3
					    	        	 ps.setNull(39,Types.NCHAR);//NO_C
					    	        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
					    	        	 ps.setNull(41,Types.NVARCHAR);//NO4
					    	        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
					    	        	 ps.setNull(43,Types.NVARCHAR);//NO5
					    	        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
					    	        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
					    	        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
					    	        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
					    	        	 ps.setNull(48,Types.NVARCHAR);//ROOM
					    	        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
					    	        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
					    	        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
					    	        	 ps.setNull(52,Types.NVARCHAR);//Lan
	        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
	        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
	        				        	 ps.setNull(55,Types.NVARCHAR);//no1
	        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
	        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
	        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
	        				        	 ps.setNull(59,Types.NVARCHAR);//no1
				        		    	ERR_CODE=6;//地址不正常
				        				errorcount++;
				        				count--;
			        				}
			        			}else{
			        				//System.out.println("ADDRESS 含2個號 or 2個段 or 2個路:"+ADDRESS);
				       	        	 ps.setNull(24,Types.NVARCHAR);//STR
				    	        	 ps.setNull(25,Types.NVARCHAR);//SEC
				    	        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
				    	        	 ps.setNull(27,Types.NVARCHAR);//LAN
				    	        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
				    	        	 ps.setNull(29,Types.NVARCHAR);//ALY
				    	        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
				    	        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
				    	        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
				    	        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
				    	        	 ps.setNull(34,Types.NVARCHAR);//NO1
				    	        	 ps.setNull(35,Types.NCHAR);//DASH1
				    	        	 ps.setNull(36,Types.NVARCHAR);//NO2
				    	        	 ps.setNull(37,Types.NCHAR);//DASH2
				    	        	 ps.setNull(38,Types.NVARCHAR);//NO3
				    	        	 ps.setNull(39,Types.NCHAR);//NO_C
				    	        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
				    	        	 ps.setNull(41,Types.NVARCHAR);//NO4
				    	        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
				    	        	 ps.setNull(43,Types.NVARCHAR);//NO5
				    	        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
				    	        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
				    	        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
				    	        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
				    	        	 ps.setNull(48,Types.NVARCHAR);//ROOM
				    	        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
				    	        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
				    	        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
				    	        	 ps.setNull(52,Types.NVARCHAR);//Lan
        				        	 ps.setNull(53,Types.NVARCHAR);//Aly
        				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
        				        	 ps.setNull(55,Types.NVARCHAR);//no1
        				        	 ps.setNull(56,Types.NVARCHAR);//Lan
        				        	 ps.setNull(57,Types.NVARCHAR);//Aly
        				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
        				        	 ps.setNull(59,Types.NVARCHAR);//no1
			        				ERR_CODE=3;//含2個號 or 2個段 or 2個路
			        				errorcount++;
			        				count--;
			        			}
		        			}else{//地址裡有鄰
		        				//System.out.println("ADDRESS 有鄰:"+ADDRESS);
			       	        	 ps.setNull(24,Types.NVARCHAR);//STR
			    	        	 ps.setNull(25,Types.NVARCHAR);//SEC
			    	        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
			    	        	 ps.setNull(27,Types.NVARCHAR);//LAN
			    	        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
			    	        	 ps.setNull(29,Types.NVARCHAR);//ALY
			    	        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
			    	        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
			    	        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
			    	        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
			    	        	 ps.setNull(34,Types.NVARCHAR);//NO1
			    	        	 ps.setNull(35,Types.NCHAR);//DASH1
			    	        	 ps.setNull(36,Types.NVARCHAR);//NO2
			    	        	 ps.setNull(37,Types.NCHAR);//DASH2
			    	        	 ps.setNull(38,Types.NVARCHAR);//NO3
			    	        	 ps.setNull(39,Types.NCHAR);//NO_C
			    	        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
			    	        	 ps.setNull(41,Types.NVARCHAR);//NO4
			    	        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
			    	        	 ps.setNull(43,Types.NVARCHAR);//NO5
			    	        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
			    	        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
			    	        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
			    	        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
			    	        	 ps.setNull(48,Types.NVARCHAR);//ROOM
			    	        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
			    	        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
			    	        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
			    	        	 ps.setNull(52,Types.NVARCHAR);//Lan
    				        	 ps.setNull(53,Types.NVARCHAR);//Aly
    				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
    				        	 ps.setNull(55,Types.NVARCHAR);//no1
    				        	 ps.setNull(56,Types.NVARCHAR);//Lan
    				        	 ps.setNull(57,Types.NVARCHAR);//Aly
    				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
    				        	 ps.setNull(59,Types.NVARCHAR);//no1
		        				ERR_CODE=5;//ADDRESS 有鄰
		        				errorcount++;
		        				count--;
		        			}
	        			}else{//有特殊符號
	        				//System.out.println("ADDRESS 有特殊符號:"+ADDRESS);
		       	        	 ps.setNull(24,Types.NVARCHAR);//STR
		    	        	 ps.setNull(25,Types.NVARCHAR);//SEC
		    	        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
		    	        	 ps.setNull(27,Types.NVARCHAR);//LAN
		    	        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
		    	        	 ps.setNull(29,Types.NVARCHAR);//ALY
		    	        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
		    	        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
		    	        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
		    	        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
		    	        	 ps.setNull(34,Types.NVARCHAR);//NO1
		    	        	 ps.setNull(35,Types.NCHAR);//DASH1
		    	        	 ps.setNull(36,Types.NVARCHAR);//NO2
		    	        	 ps.setNull(37,Types.NCHAR);//DASH2
		    	        	 ps.setNull(38,Types.NVARCHAR);//NO3
		    	        	 ps.setNull(39,Types.NCHAR);//NO_C
		    	        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
		    	        	 ps.setNull(41,Types.NVARCHAR);//NO4
		    	        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
		    	        	 ps.setNull(43,Types.NVARCHAR);//NO5
		    	        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
		    	        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
		    	        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
		    	        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
		    	        	 ps.setNull(48,Types.NVARCHAR);//ROOM
		    	        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
		    	        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
		    	        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
		    	        	 ps.setNull(52,Types.NVARCHAR);//Lan
				        	 ps.setNull(53,Types.NVARCHAR);//Aly
				        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
				        	 ps.setNull(55,Types.NVARCHAR);//no1
				        	 ps.setNull(56,Types.NVARCHAR);//Lan
				        	 ps.setNull(57,Types.NVARCHAR);//Aly
				        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
				        	 ps.setNull(59,Types.NVARCHAR);//no1
	        				ERR_CODE=0;///含特殊符號
		        			errorcount++;
		        			count--;
	        			}


	        		}else{
	        			//System.out.println("ADDRESS 含戶政 或 拆除 或 全毀:"+ADDRESS);
		   	        	 ps.setNull(24,Types.NVARCHAR);//STR
			        	 ps.setNull(25,Types.NVARCHAR);//SEC
			        	 ps.setNull(26,Types.NVARCHAR);//SEC_C
			        	 ps.setNull(27,Types.NVARCHAR);//LAN
			        	 ps.setNull(28,Types.NVARCHAR);//LAN_C
			        	 ps.setNull(29,Types.NVARCHAR);//ALY
			        	 ps.setNull(30,Types.NVARCHAR);//ALY_C
			        	 ps.setNull(31,Types.NVARCHAR);//SUB_ALY
			        	 ps.setNull(32,Types.NVARCHAR);//SUB_ALY_C
			        	 ps.setNull(33,Types.NCHAR);//SP_CHAR1
			        	 ps.setNull(34,Types.NVARCHAR);//NO1
			        	 ps.setNull(35,Types.NCHAR);//DASH1
			        	 ps.setNull(36,Types.NVARCHAR);//NO2
			        	 ps.setNull(37,Types.NCHAR);//DASH2
			        	 ps.setNull(38,Types.NVARCHAR);//NO3
			        	 ps.setNull(39,Types.NCHAR);//NO_C
			        	 ps.setNull(40,Types.NCHAR);//SP_CHAR2
			        	 ps.setNull(41,Types.NVARCHAR);//NO4
			        	 ps.setNull(42,Types.NVARCHAR);//SP_CHAR3
			        	 ps.setNull(43,Types.NVARCHAR);//NO5
			        	 ps.setNull(44,Types.NVARCHAR);//MAIN_FLOOR
			        	 ps.setNull(45,Types.NVARCHAR);//FLOOR_C1
			        	 ps.setNull(46,Types.NVARCHAR);//FLOOR_C2
			        	 ps.setNull(47,Types.NVARCHAR);//SUB_FLOOR
			        	 ps.setNull(48,Types.NVARCHAR);//ROOM
			        	 ps.setNull(49,Types.NVARCHAR);//ROOM_C
			        	 ps.setNull(50,Types.NVARCHAR);//COMMENT
			        	 ps.setNull(51,Types.NVARCHAR);//ADR_MERGE
			        	 ps.setNull(52,Types.NVARCHAR);//Lan
			        	 ps.setNull(53,Types.NVARCHAR);//Aly
			        	 ps.setNull(54,Types.NVARCHAR);//sub_aly
			        	 ps.setNull(55,Types.NVARCHAR);//no1
			        	 ps.setNull(56,Types.NVARCHAR);//Lan
			        	 ps.setNull(57,Types.NVARCHAR);//Aly
			        	 ps.setNull(58,Types.NVARCHAR);//sub_aly
			        	 ps.setNull(59,Types.NVARCHAR);//no1
	        			ERR_CODE=4;//含戶政 或 拆除 或 全毀
	        			errorcount++;
	        			count--;
	        		}
	        	}
	         } 
	         
  	         if (ERR_CODE!=-1)
  	         	 ps.setInt(60,ERR_CODE);
	         else
	        	 ps.setNull(60,Types.TINYINT);
	         
	         if (EDIT_DATE!=null)
	         	ps.setNString(61,rs.getString("NEW_EDIT_DATE").toString());
	         else
	        	 ps.setNull(61,Types.NCHAR);
	         
	         if (EDIT_TYPE!=null)
	        	 ps.setNString(62,rs.getString("EDIT_TYPE").toString());
	         else
	        	 ps.setNull(62,Types.NCHAR);
	         
	         
	         totalcount=count+errorcount;
	         ps.addBatch();
     		
     		 conn.setAutoCommit(false);
             if ((count+errorcount)%10000==0){
//              System.out.println("count: " + count);
              ps.executeBatch();
              conn.commit();
              ps.clearBatch();
              console.append("已輸入" + (count+errorcount) + "筆資料到資料庫...\n");
             }
	         
		      
	      }
	      
	      

	      System.out.println("Inserted Sucessful:共"+totalcount+"筆->"+count+"筆可分割data,"+errorcount+"筆不處理data:"+ df.format(new Date()));

	      
	      
          ps.executeBatch();
          conn.commit();
          console.append("已輸入" + (count+errorcount) + "筆資料到資料庫...\n");
          conn.setAutoCommit(true);
	      
	      rs.close();
	   }catch(SQLException se){
	      //Handle errors for JDBC
	      se.printStackTrace();
	   }catch(Exception e){
	      //Handle errors for Class.forName
	      e.printStackTrace();	     
	   }finally{
	      //finally block used to close resources
	      try{
	         if(stmt!=null){
	            conn.close();
	         }
	      }catch(SQLException se){
	      }// do nothing
	      try{
	         if(conn!=null)
	            conn.close();
	      }catch(SQLException se){
	         se.printStackTrace();
	      }//end finally try
	   }//end try
	   System.out.println("Goodbye!");
	   
	}//end main

	   private String doJob(String addrstring) throws IOException{
			//System.out.println("addrstring--->"+addrstring);
		   
			String result="";
			addrstring=addrstring.replaceAll("　", "");
			addrstring=addrstring.replaceAll(" ", "");
			addrstring=addrstring.trim();
			
			if (addrstring.contains("宮后里路"))
				addrstring=addrstring.replaceAll("宮后里路", "宮后里");//07 彰化特殊路
			if (addrstring.contains("惠明街七五巷"))
				addrstring=addrstring.replaceAll("惠明街七五巷", "惠明街７５巷");//07 彰化特殊路
			if (addrstring.contains("大智路五巷"))
				addrstring=addrstring.replaceAll("大智路五巷", "大智路５巷");//07 彰化特殊路
			
			
			//規則一:載入特殊路
			 //System.out.print("spRoad--->"+spRoad);
			for(String str:spRoad){
				if (addrstring.contains(str)){
					addrstring= addrstring.replaceAll(str,str+"@");
					//System.out.println("addrstring："+addrstring);
					isSpecialRoad=true;
					isLevelOne=true;
					isRoadStrDao=1;
					break;
				}
			}
			
			//System.out.println("addrstring："+addrstring.substring(addrstring.lastIndexOf(",")+1,addrstring.length()));
			//去除縣市別,鄉鎮市 並取代@
			addrstring=addrstring.substring(addrstring.lastIndexOf(",")+1,addrstring.length()).replaceAll("@", ",");
			//System.out.println("addrstring："+addrstring);
//			if (addrstring.contains("公路新村")){
//				System.out.println("addrstring："+addrstring);
//			}
			
			//特例取代字元
			if (addrstring.contains("－"))
				addrstring=addrstring.replaceAll("－", "之");
			if (addrstring.contains("―"))
				addrstring=addrstring.replaceAll("―", "之");
			if (addrstring.contains("–"))
				addrstring=addrstring.replaceAll("–", "之");
			if (addrstring.contains("〔"))
				addrstring=addrstring.replaceAll("〔", "（");
			if (addrstring.contains("〕"))
				addrstring=addrstring.replaceAll("〕", "）");
			if (addrstring.contains("﹙"))
				addrstring=addrstring.replaceAll("﹙", "（");
			if (addrstring.contains("﹚"))
				addrstring=addrstring.replaceAll("﹚", "）");
//			if (addrstring.contains("地下室")){
//				if(!addrstring.contains("地下室之"))
//				addrstring=addrstring.replaceAll("地下室", "地下");
//			}
			if (addrstring.contains("（臨）")){
				int index=addrstring.indexOf("）");
				if (index!=addrstring.length()-1){//只處理前面的不處理最後的
					addrstring=addrstring.replaceAll("（臨）", "臨");
				}
			}
			if (addrstring.contains("（"))
				addrstring=addrstring.replaceAll("（", ",（");
//			if (addrstring.contains("一層"))
//				addrstring=addrstring.replaceAll("一層", "一樓");
//			if (addrstring.contains("壹層"))
//				addrstring=addrstring.replaceAll("壹層", "一樓");
			if (addrstring.contains("之一"))
				addrstring=addrstring.replaceAll("之一", "之１");
			if (addrstring.contains("之二"))
				addrstring=addrstring.replaceAll("之二", "之２");
			if (addrstring.contains("之三"))
				addrstring=addrstring.replaceAll("之三", "之３");
			if (addrstring.contains("八號"))
				addrstring=addrstring.replaceAll("八號", "８號");
			if (addrstring.contains("Ｉ號"))
				addrstring=addrstring.replaceAll("Ｉ號", "１號");	
			if (addrstring.contains("ｌ號"))
				addrstring=addrstring.replaceAll("ｌ號", "１號");		
			if (addrstring.contains("一號"))
				addrstring=addrstring.replaceAll("一號", "１號");			
			if (addrstring.contains("１橫"))
				addrstring=addrstring.replaceAll("１橫", "１橫衖");

			
			
			
			if (addrstring.length()!=0 && addrstring.contains("號")){
				

				if (addrstring.contains("段")){		
					if (!addrstring.contains("段,")){		
						addrstring = addrstring.replaceAll("段","段,");
						isSec=true;
					}
				}

				String reverseString=convert3(addrstring);
				String repStr1="";
				if (reverseString.contains("號")){	
					repStr1 = reverseString.replaceFirst("號",",號");
				}
				
				if (repStr1.contains("樓")){	
					repStr1 = repStr1.replaceFirst("樓",",樓");
				}else if (repStr1.contains("層")){
					repStr1 = repStr1.replaceFirst("層",",層");
				}

				//System.out.println("isSpecialRoad："+isSpecialRoad);
				//System.out.println("repStr1："+repStr1);
				if (!isSpecialRoad){
					int roadNum=0;
					int strNum=0;
					int daoNum=0;
					if (!isLevelOne){
						//判斷路 街 道 誰的長
						if (repStr1.contains("路"))
						roadNum=repStr1.lastIndexOf("路");
						if (repStr1.contains("街"))
						strNum=repStr1.lastIndexOf("街");
						if (repStr1.contains("道"))
						daoNum=repStr1.lastIndexOf("道");
//						System.out.println("roadNum:"+roadNum);
//						System.out.println("strNum:"+strNum);
//						System.out.println("daoNum:"+daoNum);
					}
					if (roadNum!=0){
						if(strNum!=0){
							if (daoNum!=0){
								if ((roadNum<strNum) && (roadNum<daoNum)){
									isRoadStrDao=1;
								}
								if ((strNum<roadNum) && (strNum<daoNum)){
									isRoadStrDao=2;
								}
								if ((daoNum<roadNum) && (daoNum<strNum)){
									isRoadStrDao=3;
								}
							}else{// road!=0 str!=0 dao=0
								if (roadNum<strNum){
									isRoadStrDao=1;
								}
								if (strNum<roadNum){
									isRoadStrDao=2;
								}
							}
						}else{//road!=0 str=0
							if (daoNum!=0){
								if ((roadNum<daoNum)){
									isRoadStrDao=1;
								}
								if (daoNum<strNum){
									isRoadStrDao=3;
								}
							}else{// road!=0 str!=0 dao=0
								isRoadStrDao=1;
							}
						}							
					}else{//road=0
						if(strNum!=0){
							if (daoNum!=0){
								if (strNum<daoNum){
									isRoadStrDao=2;
								}
								if (daoNum<strNum){
									isRoadStrDao=3;
								}
							}else{// road=0 str!=0 dao=0
									isRoadStrDao=2;								
							}
						}else{//road=0 str=0 road
							isRoadStrDao=3;
						}					
					}
				}

				//System.out.println("isRoadStrDao:"+isRoadStrDao);
				if (!isSpecialRoad){
					if (!isLevelOne){
						if (isRoadStrDao==1){
							if (repStr1.contains("路")){	
								if (!repStr1.contains(",路")){	
									if (repStr1.contains("段上路")){;//07 特殊路 段上路路林上
										repStr1 = repStr1.replaceFirst("段上路","段上路,");
										isLevelOne = true;
									}else if (repStr1.contains("巷頂路")){//07 特殊路 巷頂路
											repStr1 = repStr1.replaceFirst("巷頂路","巷頂路,");										
									}else{
										repStr1 = repStr1.replaceFirst("路",",路");//
										isLevelOne = true;
									}
								}
							}
						}else if (isRoadStrDao==2){
							if (repStr1.contains("段街新路新芳")){//07 特殊路 段街新路新芳	
								repStr1 = repStr1.replaceFirst("段街新路新芳","段街新,路新芳");
								isLevelOne = true;
							}
						}
				}
				
				if (!isLevelOne){
					if (isRoadStrDao==2){
						if (repStr1.contains("街")){		
							if (!repStr1.contains("街,")){		
								repStr1 = repStr1.replaceFirst("街",",街");
								isLevelOne = true;
							}
						}
					}
				}
				if (!isLevelOne){
					if (isRoadStrDao==3){
						if (repStr1.contains("道")){		
							if (!repStr1.contains("道,")){		
								repStr1 = repStr1.replaceFirst("道",",道");
								isLevelOne = true;
							}
						}
					}
				}
				}
				//System.out.println("isLevelOne:"+isLevelOne);
				if (repStr1.contains("巷")){
					if (!repStr1.contains("巷,")){	
						repStr1 = repStr1.replaceAll("巷",",巷");
					}
				}
				if (repStr1.contains("弄")){
					if (!repStr1.contains("弄,")){
						repStr1 = repStr1.replaceAll("弄",",弄");
					}
				}
				if (repStr1.contains("衖")){
					if (!repStr1.contains("衖,")){
						repStr1 = repStr1.replaceAll("衖",",衖");
					}
				}else if (repStr1.contains("衕")){
					if (!repStr1.contains("衕,")){
						repStr1 = repStr1.replaceAll("衕",",衕");
					}
				}
				String revStr2 = convert3(repStr1);//將字串轉回來
				//System.out.println("result--->"+revStr2);
				if (revStr2.contains("空號,"))
					revStr2=revStr2.replaceAll("空號,", "空號");
				if (revStr2.contains(",）"))
					revStr2=revStr2.replaceAll(",）", "）");

				 String gg=fixFormat(revStr2);
				 return gg;
				
			}else{//若地址為空
				System.out.println("地址有誤！！！："+addrstring);
				return "";
			}
		}
		

		private String fixFormat(String str){//定長共17位欄位
			//System.out.println("str--->"+str);
			//先判斷第一個數字前是否是,
			int fidFistNum=findindex(str);
			//若不是,往前加一個,
			if ((fidFistNum!=0) && (!str.substring(fidFistNum-1,fidFistNum).equals(",")) && (!str.substring(fidFistNum-1,fidFistNum).equals("臨")) && (!str.substring(fidFistNum-1,fidFistNum).equals("特")) && (!str.substring(fidFistNum-1,fidFistNum).equals("附"))){
				str=preMixStr(str,fidFistNum);
			}
			
			
			
			
			//System.out.println("str--->"+str);
			String[] addStr=str.split(",");
			List<String> myList = new ArrayList<String>(Arrays.asList(str.split(",")));
			//System.out.println("myList:"+myList);
			//String output[]=new String[19];  
			String outputnew[]=new String[27];
			for(int i=0;i<myList.size();i++){
				if (isLevelOne){
					outputnew[0]=myList.get(0);				
				}
				if (isSec){
					if (myList.get(1).contains("段")){
						outputnew[1]=myList.get(1).replaceAll("段", "");
						outputnew[2]="段";
					}else{
						if((!myList.get(1).contains("樓")) && (!myList.get(1).contains("號")) && (!myList.get(1).contains("巷")) && (!myList.get(1).contains("弄")) && (!myList.get(1).contains("衖")) && (!myList.get(1).contains("衕"))){//若有特殊路段
							if (outputnew[1]!="")
								outputnew[1]=myList.get(1);
						}
					}
				}else{
					if ((myList.size()>=2) && (myList.get(1)!=null)){
						  if((!myList.get(1).contains("樓")) && (!myList.get(1).contains("號")) && (!myList.get(1).contains("巷")) && (!myList.get(1).contains("弄")) && (!myList.get(1).contains("衖")) && (!myList.get(1).contains("衕"))){//若有特殊路段
							if (outputnew[1]!="")
								outputnew[1]=myList.get(1);
							}
					}else if (myList.get(0)!=null){
						if((!myList.get(0).contains("樓")) && (!myList.get(0).contains("號")) && (!myList.get(0).contains("巷")) && (!myList.get(0).contains("弄")) && (!myList.get(0).contains("衖")) && (!myList.get(0).contains("衕"))){//若有特殊路段
							if (outputnew[1]!="")
								outputnew[1]=myList.get(1);
							}
					}
				}
				if (myList.get(i).contains("巷") || myList.get(i).contains("台化一莊")){//彰化特殊巷不顯示
					if (outputnew[3]==null){
						if (myList.get(i)!=outputnew[0]){
							if (myList.get(i).contains("台化一莊")){
								outputnew[3]="台化一莊";
							}else{
								outputnew[3]=myList.get(i).replaceAll("巷", "");
								outputnew[4]="巷";
							}
						}
					}else{
						if (myList.get(i)!=outputnew[1]){
							if (myList.get(i).equals("一橫巷") || myList.get(i).equals("二橫巷")){
								outputnew[5]=myList.get(i).replaceAll("巷", "");
								outputnew[6]="巷";
							}else{
								outputnew[5]=myList.get(i).replaceAll("巷", "");
								outputnew[6]="弄";
							}
						}
					}
				}
				if (myList.get(i).contains("弄")){
					outputnew[5]=myList.get(i).replaceAll("弄", "");
					outputnew[6]="弄";
				}
				
				if (myList.get(i).contains("衖")){
					if (myList.get(i).contains("橫衖")){//彰化特殊衖
						outputnew[7]=myList.get(i).replaceAll("橫衖", "");
						outputnew[8]="橫";
					}else{
						outputnew[7]=myList.get(i).replaceAll("衖", "");
						outputnew[8]="衖";
					}
				}else if (myList.get(i).contains("衕")){
					outputnew[7]=myList.get(i).replaceAll("衕", "");
					outputnew[8]="衕";
				}
				
				int Numofi=0;
				if (myList.get(i).contains("號") && (myList.get(i).lastIndexOf("號")==myList.get(i).length()-1)){
					Numofi=i;
					//String subStr=myList.get(i);
					//int numbInd=subStr.lastIndexOf("號");
					//if (numbInd==subStr.length()-1){
					//處理號之前
					String preNumStr=myList.get(i).replaceFirst("號", "");
					//System.out.println("preNumStr:"+preNumStr);
					int checkNum=findChar(preNumStr);
					//System.out.println("checkNum:"+checkNum);
					if (checkNum!=-1){
						boolean isNo1=false;
						//特、臨、附
						if(!isNo1){
							if ((preNumStr.contains("特")) && ((preNumStr.indexOf("特")==0))){
								outputnew[9]="特";
								preNumStr=preNumStr.replaceFirst("特", "");
								isNo1=true;
							}
						}
						if(!isNo1){
							if ((preNumStr.contains("臨")) && ((preNumStr.indexOf("臨")==0))){
								outputnew[9]="臨";
								preNumStr=preNumStr.replaceFirst("臨", "");
								isNo1=true;
							}
						}
						if(!isNo1){
							if ((preNumStr.contains("附")) && ((preNumStr.indexOf("附")==0))){
								outputnew[9]="附";
								preNumStr=preNumStr.replaceFirst("附", "");
								isNo1=true;
							}
						}
						//System.out.println("preNumStrNo1:"+preNumStr);
						int no1=findChar(preNumStr);
						//System.out.println("no1:"+no1);
						if (no1!=-1){
							outputnew[10]=preNumStr.substring(0,no1);
							outputnew[15]="號";
							//System.out.println("outputnew[10]:"+outputnew[10]);
							//後面還有資料
							preNumStr=preNumStr.substring(no1,preNumStr.length());
							//System.out.println("preNumStr:"+preNumStr);
							if (preNumStr.length()!=0){//後面還有資料
								//之、臨、附
								boolean isNo2=false;
								if(!isNo2){
									if ((preNumStr.contains("之")) && ((preNumStr.indexOf("之")==0))){
										outputnew[11]="之";
										preNumStr=preNumStr.replaceFirst("之", "");
										isNo2=true;
									}
								}
								if(!isNo2){
									if ((preNumStr.contains("臨")) && ((preNumStr.indexOf("臨")==0))){
										outputnew[11]="臨";
										preNumStr=preNumStr.replaceFirst("臨", "");
										isNo2=true;
									}
								}
								if(!isNo2){
									if ((preNumStr.contains("附")) && ((preNumStr.indexOf("附")==0))){
										outputnew[11]="附";
										preNumStr=preNumStr.replaceFirst("附", "");
										isNo2=true;
									}
								}
								//System.out.println("preNumStrNo2:"+preNumStr);
								int no2=findChar(preNumStr);
								//System.out.println("no2:"+no2);
								if (no2!=-1){
									outputnew[12]=preNumStr.substring(0,no2);								
									preNumStr=preNumStr.substring(no2,preNumStr.length());								
									if (preNumStr.length()!=0){//後面還有資料
										//之、臨、附
										boolean isNo3=false;
										if (!isNo3){
											if ((preNumStr.contains("之")) && ((preNumStr.indexOf("之")==0))){
												outputnew[13]="之";
												preNumStr=preNumStr.replaceFirst("之", "");
												isNo3=true;
											}
										}
										if (!isNo3){
											if ((preNumStr.contains("之")) && ((preNumStr.indexOf("之")==0))){
												outputnew[13]="臨";
												preNumStr=preNumStr.replaceFirst("臨", "");
												isNo3=true;
											}
										}
										if (!isNo3){
											if ((preNumStr.contains("附")) && ((preNumStr.indexOf("附")==0))){
												outputnew[13]="附";
												preNumStr=preNumStr.replaceFirst("附", "");
												isNo3=true;
											}
										}
										//System.out.println("preNumStrNo3:"+preNumStr);
										int no3=findChar(preNumStr);
										//System.out.println("no3:"+no3);
										if (no3!=-1){
											outputnew[14]=preNumStr.substring(0,no3);
										}else{//最後
											outputnew[14]=preNumStr;
										}
								}else{//最後
									outputnew[14]=preNumStr;
								}
							
								}else{//最後
									outputnew[12]=preNumStr;
								}

							}
						}else{//只有單獨號
							outputnew[10]=preNumStr;
							outputnew[15]="號";
						}

					}else{//只有單獨號
						outputnew[10]=preNumStr;
						outputnew[15]="號";
						
					}
				//}
				}

				if (Numofi!=0){//處理號之後
					//String subStr=myList.get(i);
					//int numbInd=subStr.lastIndexOf("號");
					//if (numbInd==subStr.length()-1){
					//處理號之後
					if ((i+1<=myList.size()-1) && (myList.get(i+1).length()>0)){
						//System.out.println("號之後長度"+myList.get(i+1).length());
						String afeterNumStr=myList.get(i+1);
						//System.out.println("myList.get(i+1)"+myList.get(i+1));
						boolean isChar1=false;//是否有之、臨、附、頂 如果沒有直接處理樓
						if (afeterNumStr.length()!=0){//後面還有資料
							//之、臨、附、頂、底、地下、 地下之
							if(afeterNumStr.contains("之") || afeterNumStr.contains("（臨）") || afeterNumStr.contains("臨") || afeterNumStr.contains("附") || afeterNumStr.contains("頂") || afeterNumStr.contains("底") || afeterNumStr.contains("地下") || afeterNumStr.contains("地下之") || afeterNumStr.contains("地下室") || afeterNumStr.contains("地上")){								
								isChar1=true;
							}
							//System.out.println("isChar1"+isChar1);			
							boolean isNo4=false;
							if (isChar1){
								if (!isNo4){
									if (!afeterNumStr.contains("室之")){
										if ((afeterNumStr.contains("之")) && ((afeterNumStr.indexOf("之")==0))){
											outputnew[16]="之";
											afeterNumStr=afeterNumStr.replaceFirst("之", "");
											isNo4=true;
										}
									}
								}
								if (!isNo4){
									if ((afeterNumStr.contains("臨")) && ((afeterNumStr.indexOf("臨")==0))){
										outputnew[16]="臨";
										afeterNumStr=afeterNumStr.replaceFirst("臨", "");
										isNo4=true;
									}
								}
								if (!isNo4){
									if ((afeterNumStr.contains("附")) && ((afeterNumStr.indexOf("附")==0))){
										outputnew[16]="附";
										afeterNumStr=afeterNumStr.replaceFirst("附", "");
										isNo4=true;
									}
								}
								if (!isNo4){
									if ((afeterNumStr.contains("頂")) && ((afeterNumStr.indexOf("頂")==0))){
										outputnew[16]="頂";
										afeterNumStr=afeterNumStr.replaceFirst("頂", "");
										isNo4=true;
									}
								}
								//System.out.println("afeterNumStrNo4:"+afeterNumStr);
								int no4=findChar(afeterNumStr);
								//System.out.println("no4:"+no4);
								if (no4!=-1){
									outputnew[17]=afeterNumStr.substring(0,no4);
									afeterNumStr=afeterNumStr.substring(no4,afeterNumStr.length());
									boolean isChar2=false;//是否有底、地下、 地下之 如果沒有直接處理樓
									if (afeterNumStr.length()!=0){//後面還有資料
										//底、地下、 地下之、地下室、地上
										if (!isChar2){
											if ((afeterNumStr.contains("底")) && ((afeterNumStr.indexOf("底")==0))){
												outputnew[18]="底";
												afeterNumStr=afeterNumStr.replaceFirst("底", "");
												isChar2=true;
											}
										}
										if (!isChar2){
											if ((afeterNumStr.contains("地")) && ((afeterNumStr.indexOf("地")==0))){
												if (afeterNumStr.contains("地下室")){
													outputnew[18]="地下室";
													afeterNumStr=afeterNumStr.replaceFirst("地下室", "");
													isChar2=true;
												}else if (afeterNumStr.contains("地下之")){
													outputnew[18]="地下之";
													afeterNumStr=afeterNumStr.replaceFirst("地下之", "");
													isChar2=true;
												}else{
													if (!isChar2){
														if (afeterNumStr.contains("地下")){
															outputnew[18]="地下";
															afeterNumStr=afeterNumStr.replaceFirst("地下", "");
															isChar2=true;
														}else if (afeterNumStr.contains("地上")){
															outputnew[18]="地上";
															afeterNumStr=afeterNumStr.replaceFirst("地上", "");
															isChar2=true;
														}else if(afeterNumStr.contains("附")){
															outputnew[18]="附";
															afeterNumStr=afeterNumStr.replaceFirst("附", "");
															isChar2=true;
														}
													}
												}
											}
										}
										//System.out.println("afterNumStrNo5:"+afeterNumStr);
										if (isChar2){
											int no5=findChar(afeterNumStr);
											//System.out.println("no5:"+no5);
											if (no5!=-1){
												if (no5!=0)
													outputnew[19]=afeterNumStr.substring(0,no5);
												afeterNumStr=afeterNumStr.substring(no5,afeterNumStr.length());
												//System.out.println("afeterNumStr:"+afeterNumStr);
												if (afeterNumStr.length()!=0){//後面還有資料 樓之前
													if (afeterNumStr.contains("樓")){
														afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("樓"));
														outputnew[20]=transferNum(afeterNumStr);//全形數字判斷	
														outputnew[21]="樓";
													}else if (afeterNumStr.contains("層")){//寫錯字樓->層
														afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("層"));
														outputnew[20]=transferNum(afeterNumStr);
														outputnew[21]="層";
													}else{
														if ((!afeterNumStr.contains("（")) && ((!afeterNumStr.contains("）")))){
															outputnew[24]=afeterNumStr;//還有字放室之前的牽引字串
														}else{
															//System.out.println("註解:");
															outputnew[26]=afeterNumStr;//註解
														}
													}
												}
												
											}else{//最後
												outputnew[19]=afeterNumStr;
											}
										}else{//只處理樓
											//System.out.println("無 底、地下、 地下之、 地下室、 地上 :只處理樓");
											//System.out.println("afeterNumStr:"+afeterNumStr);
											if (afeterNumStr.length()!=0){//後面還有資料 樓之前
												
												if (afeterNumStr.contains("樓")){
													afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("樓"));
													outputnew[20]=transferNum(afeterNumStr);//全形數字判斷	
													outputnew[21]="樓";
												}else if (afeterNumStr.contains("層")){//寫錯字樓->層
													afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("層"));
													outputnew[20]=transferNum(afeterNumStr);
													outputnew[21]="層";
												}else{
													if ((!afeterNumStr.contains("（")) && ((!afeterNumStr.contains("）")))){
														outputnew[24]=afeterNumStr;//還有字放室之前的牽引字串
													}else{
														//System.out.println("註解:");
														outputnew[26]=afeterNumStr;//註解
													}
												}
												
											}
										}
									
									}
									
									
									
								}else{//最後
									outputnew[17]=afeterNumStr;
								}
							}else{//只處理樓
								//System.out.println("無 之、臨、附、頂、底、地下、 地下之、 地下室 、 地上  :只處理樓");
								//System.out.println("afeterNumStr:"+afeterNumStr);
								if (afeterNumStr.length()!=0){//後面還有資料 樓之前
									if (afeterNumStr.contains("樓")){
										afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("樓"));
										outputnew[20]=transferNum(afeterNumStr);//全形數字判斷	
										outputnew[21]="樓";
									}else if (afeterNumStr.contains("層")){//寫錯字樓->層
										afeterNumStr=afeterNumStr.substring(0,afeterNumStr.indexOf("層"));
										outputnew[20]=transferNum(afeterNumStr);
										outputnew[21]="層";
									}else{
										if ((!afeterNumStr.contains("（")) && ((!afeterNumStr.contains("）")))){
											outputnew[24]=afeterNumStr;//還有字放室之前的牽引字串
										}else{
											//System.out.println("註解:");
											outputnew[26]=afeterNumStr;//註解
										}
									}
								}
							}
					}
					}
				//}
				}
				
				if(myList.get(i).contains("樓") || myList.get(i).contains("層")){
					String subStr=myList.get(i);
					int numbInd=0;
					if(myList.get(i).contains("樓"))
						numbInd=subStr.lastIndexOf("樓");
					if(myList.get(i).contains("層"))
						numbInd=subStr.lastIndexOf("層");
					if (numbInd==subStr.length()-1){
					//處理樓之後
					//System.out.println("處理樓之後");
					if ((i+1<=myList.size()-1) && (myList.get(i+1).length()>0)){
						//System.out.println("樓之後長度"+myList.get(i+1).length());
						String afeterFloorStr=myList.get(i+1);
						//System.out.println("afeterFloorStr"+afeterFloorStr);
						boolean isSubFloor=false;
						if (afeterFloorStr.length()!=0){//後面還有資料
							//之
							if (afeterFloorStr.contains("之")){
								afeterFloorStr=afeterFloorStr.replaceFirst("之", "");
								outputnew[22]="之";
								isSubFloor=true;
							}
							//System.out.println("afeterFloorStr"+afeterFloorStr);
							if (isSubFloor){
								int subfloor=findChar(afeterFloorStr);
								//System.out.println("subfloor"+subfloor);
								if (subfloor!=-1){
									if (subfloor!=0)
										outputnew[23]=afeterFloorStr.substring(0,subfloor);
									afeterFloorStr=afeterFloorStr.substring(subfloor,afeterFloorStr.length());
									if ((!afeterFloorStr.contains("（")) && ((!afeterFloorStr.contains("）")))){//（註解不處理
										if (afeterFloorStr.contains("室")){
											outputnew[24]=afeterFloorStr.replaceFirst("室", "");
											outputnew[25]="室";
										}else{
											outputnew[24]=afeterFloorStr;
										}
									}else{
										outputnew[26]=afeterFloorStr;
									}
									
								}else{//最後
									outputnew[23]=afeterFloorStr;
								}
							}else{//若樓之後不是不含之
								outputnew[24]=afeterFloorStr;
							}
						}
					}
				}
				}
				
				if ((myList.get(i).contains("（")) && (myList.get(i).contains("）"))){//註解
					//System.out.println("註解:"+outputnew[26]);
					if (outputnew[26]==null)
					outputnew[26]=myList.get(i);
				}
			}
			
			StringBuilder sb = new StringBuilder();
			for(int i=0;i<outputnew.length;i++){
				//System.out.println("output["+i+"]:"+output[i]);
				if (i!=outputnew.length-1){
					if (outputnew[i]!=null)
						sb.append(outputnew[i]+",");
					else
						sb.append(""+",");
				}else{
					if (outputnew[i]!=null)
						sb.append(outputnew[i]);
					else
						sb.append("");
				}
			}
			
//			//校正資料
//			Map map = new HashMap();
//			for (int i = 0; i < output.length; i++) {
//				   
//				 String e = (String) output[i];
//				 map.put(output[i], output[i]);
//			}
//			 
//			for (int i = 0; i < myList.size(); i++) {
//				String str1 = (String) myList.get(i);
//				if (str1.contains("號"))
//					str1=str1.replaceAll("號", "");
//				if (str1.contains("巷"))
//					str1=str1.replaceAll("巷", "");
//				if (str1.contains("弄"))
//					str1=str1.replaceAll("弄", "");
//				if (str1.contains("衖"))
//					str1=str1.replaceAll("衖", "");
//				if (str1.contains("衕"))
//					str1=str1.replaceAll("衕", "");
//				if (str1.contains("樓"))
//					str1=str1.replaceAll("樓", "");  
//				if (map.get(str1) == null) {
//					for(int j=0;j < output.length; i++){
//						if (output[j]==null){
//							output[j]=str1;
//						}
//					}
//				}
//			
//			}
			
			//System.out.println("finally:"+sb.toString());
			return sb.toString();
			
		}
		
		private String transferNum2(String str){//國字轉全形數字
			String result="";
			String num = "１２３４５６７８９０";
			String chars = "一二三四五六七八九十";
			
			Pattern p = Pattern.compile(chars);
			Matcher m = p.matcher(str);
			//System.out.println(str+"是否全是國字:"+m.find());
			
			
			if (str.length()==1){//個位數
				if (chars.contains(str) && !num.contains(str)){
//		        	System.out.print("含全形數字->");
//		        	System.out.println("str:"+str);
					if (str.equals("一")){
					     result+= "１";
					}else if (str.equals("二")){
						 result+= "２";
					}else if (str.equals("三")){
						 result+= "３";
					}else if (str.equals("四")){
						 result+= "４";
					}else if (str.equals("五")){
						 result+= "５";
					}else if (str.equals("六")){
						 result+= "６";
					}else if (str.equals("七")){
						 result+= "７";
					}else if (str.equals("八")){
						 result+= "８";
					}else if (str.equals("九")){
						 result+= "９";
					}else if (str.equals("十")){
						 result+= "１";
					}
					
		        }else{
		        	result=str;
		        }
			}else if (str.length()==2){
				String subStr1="";
					if (str.contains("十"))
						subStr1=str.replace("十", "");
				subStr1=str.substring(0,1);
				if (chars.contains(subStr1) && !num.contains(subStr1)){
					if (subStr1.equals("一")){
					     result+= "１";
					}else if (subStr1.equals("二")){
						 result+= "２";
					}else if (subStr1.equals("三")){
						 result+= "３";
					}else if (subStr1.equals("四")){
						 result+= "４";
					}else if (subStr1.equals("五")){
						 result+= "５";
					}else if (subStr1.equals("六")){
						 result+= "６";
					}else if (subStr1.equals("七")){
						 result+= "７";
					}else if (subStr1.equals("八")){
						 result+= "８";
					}else if (subStr1.equals("九")){
						 result+= "９";
					}
					
					result+=transferNum2(str.substring(1,2));	
				}else{
					result+=subStr1+transferNum2(str.substring(1,2));	
				}
			}else{
				result=str;
			}
				
				
			return result;
	       
		} 
		
		private String transferNum(String str){//全形數字轉國字
			String result="";
			String num = "１２３４５６７８９０";
//	        Pattern pat = Pattern.compile(regEx);
//	        Matcher mat = pat.matcher(str);
			//System.out.print("str.length()->"+str.length());
			if (str.length()==1){//個位數
		        if (num.contains(str)){
//		        	System.out.print("含全形數字->");
//		        	System.out.println("str:"+str);
					if (str.equals("１")){
					     result+= "一";
					}else if (str.equals("２")){
						 result+= "二";
					}else if (str.equals("３")){
						 result+= "三";
					}else if (str.equals("４")){
						 result+= "四";
					}else if (str.equals("５")){
						 result+= "五";
					}else if (str.equals("６")){
						 result+= "六";
					}else if (str.equals("７")){
						 result+= "七";
					}else if (str.equals("８")){
						 result+= "八";
					}else if (str.equals("９")){
						 result+= "九";
					}
					
		        }else{
		        	result=str;
		        }
			}else if (str.length()==2){
				String subStr1=str.substring(0,1);
//				System.out.print("含2位全形數字->");
				if (num.contains(subStr1)){
				if (subStr1.equals("１")){
				     result+="十";
				}else if (subStr1.equals("２")){
					 result+= "二十";
				}else if (subStr1.equals("３")){
					 result+= "三十";
				}else if (subStr1.equals("４")){
					 result+= "四十";
				}else if (subStr1.equals("５")){
					 result+= "五十";
				}else if (subStr1.equals("６")){
					 result+= "六十";
				}else if (subStr1.equals("７")){
					 result+= "七十";
				}else if (subStr1.equals("８")){
					 result+= "八十";
				}else if (subStr1.equals("９")){
					 result+= "九十";
				}
					result+=transferNum(str.substring(1,2));	
				}else{
					result+=subStr1+transferNum(str.substring(1,2));	
				}
			}
				

			return result;
	       
		} 
		
		private String lastMixStr(String str,int ind){
			return str.substring(0,ind)+","+str.substring(ind,str.length());
		}
		
		private String preMixStr(String str,int ind){
			return str.substring(0,ind)+","+str.substring(ind,str.length());
		}
		
		
		private int findindex(String s){
			String num ="１２３４５６７８９０";
	        //找newString 第一個數字=
	        int index=0;     
	        	for(int i=0;i<s.length();i++){
	        		String subString=s.substring(i,i+1);
	        		//System.out.println("subString="+subString);
	        		if (num.contains(subString)){
	        			return i;
	        		}
	        	}
				return index;
		}
		
		private int lastindex(String s){//從後往前找index
			String num ="１２３４５６７８９０";
	        //找newString 第一個數字=
	        int index=-1;     
	        	for(int i=s.length();i>0;i--){
	        		String subString=s.substring(i-1,i);
	        		if (num.contains(subString)){
	        			return i;
	        		}
	        	}
				return -1;
		}
		
		private int findChar(String str){
			String num ="１２３４５６７８９０"; 
			int index=-1;
			for(int i = 0;i<str.length();i++){
				String subString=str.substring(i,i+1);
				if(!num.contains(subString)){
					return i;
				}
			}  	
			return index;
		}
		//字串倒轉
		private String convert3(String s){
			StringBuffer sb = new StringBuffer(s);
			return sb.reverse().toString(); 
			  
		}
		
		//拿特殊路比對
		private List<String> getSpecialRoad() throws IOException{
			Connection conn = null;
			Statement stmt = null;
	        List<String> result=new ArrayList<String>();
	        try {
				Class.forName(JDBC_DRIVER);
			      //STEP 3: Open a connection
			      //System.out.println("Connecting to a selected database...");
			      conn = DriverManager.getConnection(DB_URL, USER, PASS);
			      //System.out.println("Connected database successfully...");
			      
			      //STEP 4: Execute a query
			      //System.out.println("Creating statement...");
			      stmt = conn.createStatement();
			      String sql="SELECT CONCAT(county_name,',',town_name,',',str) as keyword  FROM [dbo].[ADR_STR_TAB_SPEC] order by str DESC";
			      ResultSet rs = stmt.executeQuery(sql);
			      while(rs.next()){	
			    	  result.add(rs.getString("keyword"));
			      }
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
			      //finally block used to close resources
			      try{
			         if(stmt!=null){
			            conn.close();
			         }
			      }catch(SQLException se){
			      }// do nothing
			      try{
			         if(conn!=null)
			            conn.close();
			      }catch(SQLException se){
			         se.printStackTrace();
			      }//end finally try
			   }//end try

	        //System.out.println("post--->"+result);
			return result;
		}
		
		//載入POST檔
		private List<String> getPost(){
			java.text.SimpleDateFormat df = new java.text.SimpleDateFormat();  
			Connection conn = null;
			Statement stmt = null;
	        List<String> result=new ArrayList<String>();
	        try {
				Class.forName(JDBC_DRIVER);
			      //STEP 3: Open a connection
			      //System.out.println("Connecting to a selected database...");
			      conn = DriverManager.getConnection(DB_URL, USER, PASS);
			      //System.out.println("Connected database successfully...");
			      
			      //STEP 4: Execute a query
			      //System.out.println("Creating statement...");
			      stmt = conn.createStatement();
			      String sql="SELECT CONCAT(AREA_TOWN,ADR_ALY) as keyword  FROM [dbo].[ADR_POST]";
			      ResultSet rs = stmt.executeQuery(sql);

			      //STEP 5: Extract data from result set
			      //System.out.println("輸入:"+ df.format(new Date()));
			      
			      while(rs.next()){	
			    	  result.add(rs.getString("keyword"));
			      }
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally{
			      //finally block used to close resources
			      try{
			         if(stmt!=null){
			            conn.close();
			         }
			      }catch(SQLException se){
			      }// do nothing
			      try{
			         if(conn!=null)
			            conn.close();
			      }catch(SQLException se){
			         se.printStackTrace();
			      }//end finally try
			   }//end try

	        //System.out.println("post--->"+result);
			return result;
		}
		
		private boolean isContainTwoNum(String str){
			int indNum=str.indexOf("號");
			if (indNum==str.length()-1){//最後一個是號
				return false;
			}else{
				 //最後一個不是號
				 if (str.contains("號路")||str.contains("號巷")||str.contains("號弄")||str.contains("空號")){
					 if (str.contains("號路")){
						int index1= str.indexOf("號路");
						String Str1=str.substring(index1+2, str.length());
						return isContainTwoNum(Str1);
					 }
					 if (str.contains("號巷")){
							int index1= str.indexOf("號巷");
							String Str1=str.substring(index1+2, str.length());
							return isContainTwoNum(Str1);
					 }
					 if (str.contains("號弄")){
							int index1= str.indexOf("號弄");
							String Str1=str.substring(index1+2, str.length());
							return isContainTwoNum(Str1);
					 }
					 if (str.contains("空號")){
							String Str1=str.replaceFirst("空號", "");
							return isContainTwoNum(Str1);
					 }
					 
				 }else{
					 String Str2=str.replaceFirst("號", "");
					 if (Str2.contains("號")){
						 return true;
					 }else{
						 return false;
					 }
							 
				 }
			}
			return false;
		}
		
		private boolean isContainTwoSec(String str){
			String Str1=str.replaceFirst("段", "");
			if (!Str1.contains("段")){
				return false;
			}else{
				return true;		 
			}

		}
		
		private boolean isContainTwoRoad(String str){
			if (!str.contains("上林路路上段") && !str.contains("路平路") && !str.contains("路頂巷") ){//07 彰化特殊路
				String Str1=str.replaceFirst("路", "");
				if (!Str1.contains("路")){
					return false;
				}else{
					return true;		 
				}
			}else{
				if (str.contains("上林路路上段")){
					str=str.replace("上林路路上段", "");
				}else if(str.contains("路平路")){
					str=str.replace("路平路", "");
				}else if(str.contains("路頂巷")){
					str=str.replace("路頂巷", "");
				}
				return isContainTwoRoad(str);
			}

		}
		
		private boolean isExtChar(String str){//判斷全形符號
			String regEx = "[`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*——+|{}【】．‘；：”“’。，、？]";
			if (!str.contains("（")){
				Pattern p = Pattern.compile(regEx);
				Matcher m = p.matcher(str);
				return m.find();
			}else{
				if (!str.contains("（臨）")){
					int index=str.indexOf("（");
					//System.out.println("index:"+index);
					String str2=str.substring(0,index);
					//System.out.println("str2:"+str2);
					return isExtChar(str2);
				}else{
					String str2=str.replaceAll("（臨）", "臨");
					return isExtChar(str2);
				}
			}

		}
		
//		private boolean isContainTwoLane(String str){
//			String Str1=str.replaceFirst("巷", "");
//			if (!Str1.contains("巷")){
//				return false;
//			}else{
//				if (Str1.contains("一橫巷")){
//					return false;
//				}else{
//					return true;		 
//				}		 
//			}
//
//		}
		
		private boolean isContainNEIG(String str){//地址是否有鄰
			String num ="１２３４５６７８９０"; 
			int index=str.indexOf("鄰");
			if (index!=-1){
				if (index==str.length()-1){
					return true;
				}else{
					String subStr=str.substring(index-1,index);
					if (num.contains(subStr)){
						return true;
					}else{
						return false;
					}
				}
			}else{
				return false;
			}
		}
		
		private boolean isNumSec(String str){//數字段
			String num ="一二三四五六七八九十"; 
			int index=str.indexOf("段");
			if (index!=-1){
				if (index==str.length()-1){
					return false;
				}else{
					String subStr=str.substring(index-1,index);
					if (num.contains(subStr)){
						return true;
					}else{
						return false;
					}
				}
			}else{
				return false;
			}
		}
}
